✓ Accepted answer
First of all, don't use game.Workspace, even though it's technically down to preference, workspace is much shorter and easier to use.
Second, you should tab your code, this makes it easier to read.
Third, you don't need the ~= nil on line 2, it's just redundant.
Fourth, there is an event called TouchEnded(), this fires when something moves off a part.
In context it would look like this...
workspace.LobbyMusic.Touched:connect(function(obj)
local Model = obj.Parent
if Model:FindFirstChild("Humanoid") then
script.Parent:Play()
Model.Humanoid.Died:connect(function()
script.Parent:Stop()
end)
end
end)
workspace.LobbyMusic.TouchEnded:connect(fucntion(obj)
local Model = obj.Parent
if Model:FindFirstChild("Humanoid") then
script.Parent:Stop()
end
end)
I hope this helps! (I've also tabbed code for you)
1 comment
It very much did thank you!