Okay, there is a problem, everything works fine but when I add Sound:Play()
it would work the first few times then the script would just break and the other parts don’t even turn green and or play any sound.
here is my code:
game.StarterPlayer.StarterCharacterScripts:WaitForChild("Checkpoints")
game.StarterPlayer.StarterCharacterScripts.Checkpoints:WaitForChild("Sound")
game.Workspace:WaitForChild("CheckpointsFolder")
local sound = script:WaitForChild("Sound")
local checkpointsFolder = game.Workspace:WaitForChild("CheckpointsFolder")
local green = BrickColor.new("Lime green")
for i, v in pairs(checkpointsFolder:GetChildren()) do
v.Touched:Connect(function()
if v.BrickColor == green then
print("Already green")
else
v.BrickColor = BrickColor.new("Lime green")
sound:Play()
end
end)
end
here sit the checkpoint script, showing to incase this is breaking the script.
local Players = game:GetService("Players")
local ServerStorage = game:GetService("ServerStorage")
local checkpoint = script.Parent
function onTouched(hit)
if hit and hit.Parent and hit.Parent:FindFirstChildOfClass("Humanoid") then
local player = Players:GetPlayerFromCharacter(hit.Parent)
local checkpointData = ServerStorage:FindFirstChild("CheckpointData")
if not checkpointData then
checkpointData = Instance.new("Folder")
checkpointData.Name = "CheckpointData"
checkpointData.Parent = ServerStorage
end
local userIdString = tostring(player.UserId)
local checkpointValue = checkpointData:FindFirstChild(userIdString)
if not checkpointValue then
checkpointValue = Instance.new("ObjectValue")
checkpointValue.Name = userIdString
checkpointValue.Parent = checkpointData
player.CharacterAdded:connect(function(character)
wait()
local storedCheckpoint = ServerStorage.CheckpointData[userIdString].Value
character:MoveTo(storedCheckpoint.Position + Vector3.new(math.random(-4, 4), 4, math.random(-4, 4)))
end)
end
checkpointValue.Value = checkpoint
end
end
checkpoint.Touched:Connect(onTouched)
some screenshots:
(ignor the particle)
here is a video:
https://gyazo.com/0cd9e32127b6c731596d670eadce2e2a (dont mind the clickbait title lol)
Maybe I should use remote events? if so please guide me
note: I’m currently bashing my head against my keyboard trying to solve this problem for two days