#music script system
35 messages · Page 1 of 1 (latest)
ive got the this much done but im not sure how to aproach detecting if the player is in the part or not
somone pls help meh
-- 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
i appricate u writing a whole script for me! imma test it rn
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
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
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
Any errors?
@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
There’s no errors
I’ll test it as soon as I get home after school
But I appreciate the help 
here is the script i got rn and it doesnt work
should i put the songs inside of the script
They're undersound service so it shouldn't matter but sure try putting em inside the script. I tested it and it works at intended man
im so confused bro is there like a special property that needs to be on or off in like the part or something
CanTouch should be enabled
it is