#music script system

35 messages · Page 1 of 1 (latest)

cinder viper
#

i want to make it so that when the play button is pressed the entertainer song plays unless you walk into a part in the workspace named shop detector and then i want it to play shop music

#

ive got the this much done but im not sure how to aproach detecting if the player is in the part or not

cinder viper
#

somone pls help meh

pale quest
# cinder viper i want to make it so that when the play button is pressed the entertainer song ...
-- THIS MUST BE INSIDE OF A LOCAL SCRIPT

local runService = game:GetService("RunService")
local playersService = game:GetService("Players")
local player = playersService.LocalPlayer

local zones, status = { -- ADD YOUR OWN PARTS THAT DEFINE ZONES IN HERE
    workspace.ShopZonePart,
    workspace.LobbyZonePart,
}, nil

function playerStatus()
    if status[3] == 1 then
        if status[2] == "ShopZonePart" then
            -- PLAY SHOP MUSIC
        end
    elseif status[3] == 2 then
        if status[2] == "ShopZonePart" then
            -- STOP SHOP MUSIC
        end
    end
end

runService.Heartbeat:Connect(function(deltaTime)
    local newStatus = nil

    for i = 1, #zones do
        local hits = workspace:GetPartsInPart(zones[i])
        for j = 1, #hits do
            task.wait()
            
            local target = playersService:GetPlayerFromCharacter(hits[j].Parent) or nil
            if target == nil or target ~= player then continue end
            
            if status ~= nil and zones[i].Name == status[2] then
                newStatus = {player, zones[i].Name, 0}
                break
            elseif status == nil then
                newStatus = {player, zones[i].Name, 1}
                break
            end
            
            newStatus = nil
        end        
    end
    
    if newStatus == nil then
        status = {player, status[2], 2}
        playerStatus()
    else
        status = newStatus
        playerStatus()
    end
end)
#

Try this lil script I wrote for ya, put it in a local script and add your own Zones in the zones table.

#

In this function you'll be able to see what zones the player entered and run a function accordingly

cinder viper
#

i am extremly confused with this script and its not working so idk if i didnt something wrong

#

is there a certain place i need to put the local script

#

heres what i have in my local script

pale quest
#

Uff well firstly you need to add your own parts in this table

#

Those are the zones the script will check if the player is in

cinder viper
#

but those are what the parts are called

#

shop detector and house detector

pale quest
#

Alright next this function will return what zone the player has entered or left

#

You need to change this to whatever zone you want the shop music to play in

#
function playerStatus()
    if status[3] == 1 then
        if status[2] == "shopDetector" then
            -- PLAY SHOP MUSIC
        end
        if status[2] == "houseDetector" then
            -- PLAY HOUSE MUSIC
        end
    elseif status[3] == 2 then
        if status[2] == "shopDetector" then
            -- STOP SHOP MUSIC
        end
        if status[2] == "houseDetector" then
            -- STOP HOUSE MUSIC
        end
    end
end
#

Here's how you can scale it to other zones

cinder viper
#

heres what i got now and its not playing music

pale quest
pale quest
#

@cinder viper


local playerService = game:GetService("Players")
local player = playerService.LocalPlayer

local currentlyIn = nil

local zones = {
    {workspace.ShopZonePart, script.ShopTheme},
    {workspace.LobbyZonePart, script.LobbyTheme}
}

function isLocalPlayer(hit, zone)
    local target = playerService:GetPlayerFromCharacter(hit.Parent) or nil
    if target == nil or target ~= player then return false end
    if currentlyIn == zone then return false end
    return true
end

for i = 1, #zones do
    zones[i][1].Touched:Connect(function(hit)
        if not isLocalPlayer(hit, zones[i]) then return end
        zones[i][2]:Play()
        currentlyIn = zones[i]
    end)
    
    zones[i][1].TouchEnded:Connect(function(hit)
        if not isLocalPlayer(hit) then return end
        zones[i][2]:Stop()
        currentlyIn = nil
    end)
end

Alright here's a simple not overcomplicated version haha

#

I tested this one and it works

#

Just add the {PartZone, Music} in that table and everything will work as intended

cinder viper
cinder viper
#

But I appreciate the help heehehuua

pale quest
cinder viper
#

here is the script i got rn and it doesnt work

cinder viper
pale quest
cinder viper
cinder viper
#

it is