Hey, I have this script in the StarterPlayerScripts

When the player touches a part it makes the beam disappear.
Shown here in Roblox Studio: https://gyazo.com/1bf0eeaa7caa45c2ab26f8491e293c2d
However, in the actual game the beam isn’t disappearing. Am I not using StarterPlayerScripts correctly? (No errors show up in studio)
Script:
local StopHaystackGPS = workspace:WaitForChild("StopHaystackGPS")
local StopDumpsterGPS = workspace:WaitForChild("DumpsterGPS")
local StopTreePlantingGPS = workspace:FindFirstChild("TreePlantingGPSStop")
local Player = game.Players.LocalPlayer.Name
local Humanoid = workspace:WaitForChild(Player,20):FindFirstChild("HumanoidRootPart")
StopHaystackGPS.Touched:Connect(function()
if Humanoid:FindFirstChild("HaystackGPSAttachment") then
Humanoid:FindFirstChild("HaystackGPSAttachment"):Destroy()
Humanoid:FindFirstChild("Beam"):Destroy()
end
wait(60)
end)
StopDumpsterGPS.Touched:Connect(function()
if Humanoid:FindFirstChild("DumpsterGPSAttachment") then
Humanoid:FindFirstChild("DumpsterGPSAttachment"):Destroy()
Humanoid:FindFirstChild("Beam"):Destroy()
end
wait(60)
end)
StopTreePlantingGPS.Touched:Connect(function()
if Humanoid:FindFirstChild("TreePlantingGPSAttachment") then
Humanoid:FindFirstChild("TreePlantingGPSAttachment"):Destroy()
Humanoid:FindFirstChild("Beam"):Destroy()
end
wait(120)
end)
Thank you!
There could be issues with the way you’re using FindFirstChild and WaitForChild. FindFirstChild will only look for an object once, but it won’t cause an error if there isn’t one and will instead return “nil
”. WaitForChild will constantly wait for the object. Also, make sure that your game is published as it can be easy to forget (I’ve done this and have seen other people on the DevFourm do the same thing). Hope this helps!
From the looks of things, it could be the way you told it to find the HumanoidRootPart, since this is in a localscript, perhaps try
local StopHaystackGPS = workspace:WaitForChild("StopHaystackGPS")
local StopDumpsterGPS = workspace:WaitForChild("DumpsterGPS")
local StopTreePlantingGPS = workspace:WaitForChild("TreePlantingGPSStop")
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:FindFirstChild("HumanoidRootPart")
local HaystackDeb = false
local DumpsterDeb = false
local TreePlantDeb = false
StopHaystackGPS.Touched:Connect(function()
print(Humanoid:FindFirstChild("HaystackGPSAttachment"))
if Humanoid:FindFirstChild("HaystackGPSAttachment") and not HaystackDeb then
HaystackDeb = true
Humanoid:FindFirstChild("HaystackGPSAttachment"):Destroy()
Humanoid:FindFirstChild("Beam"):Destroy()
wait(60)
HaystackDeb = false
end
end)
StopDumpsterGPS.Touched:Connect(function()
print(Humanoid:FindFirstChild("DumpsterGPSAttachment"))
if Humanoid:FindFirstChild("DumpsterGPSAttachment") and not DumpsterDeb then
DumpsterDeb = true
Humanoid:FindFirstChild("DumpsterGPSAttachment"):Destroy()
Humanoid:FindFirstChild("Beam"):Destroy()
wait(60)
DumpsterDeb = false
end
end)
StopTreePlantingGPS.Touched:Connect(function()
print(Humanoid:FindFirstChild("TreePlantingGPSAttachment"))
if Humanoid:FindFirstChild("TreePlantingGPSAttachment") and not TreePlantDeb then
TreePlantDeb = true
Humanoid:FindFirstChild("TreePlantingGPSAttachment"):Destroy()
Humanoid:FindFirstChild("Beam"):Destroy()
wait(120)
TreePlantDeb = false
end
end)
I also changed some thigns to suit your waits since waits alone cannot make events stop doing anything, you need debounces for that, which I provided in the code. I also placed prints in each of the touched events to see if the events are actually being fired and to confirm if it’s finding the attachments
1 Like