What I'm trying to do: Enable the script if I stay on the platform and disable the script if I leave the platform(part).
local Player = game:GetService("Players") local debounce = false function Touched(hit) if debounce == false then local player = Player:GetPlayerFromCharacter(hit.Parent) player:FindFirstChild("StarterGui").Animations.AnimationList.Animationcontroller.Disabled = false debounce = true end end function TouchEnded(hit) if debounce == true then local player = Player:GetPlayerFromCharacter(hit.Parent) player:FindFirstChild("StarterGui").Animations.AnimationList.Animationcontroller.Disabled = true debounce = false end end script.Parent.Touched:Connect(Touched) script.Parent.TouchEnded:Connect(TouchEnded)
But the studio says:
Workspace.Plot.Disabler:7: attempt to index nil with 'FindFirstChild'
I don't know what to do any suggestions?
The players gui isn't called StarterGui. It is called PlayerGui
. StarterGui
is the gui players are given upon joining the game.
So I figured out the findFirstchild problem but the script keeps rapidly enable/disable when I touch the part(Plot).
local Player = game:GetService("Players") local debounce = false function Touched(hit) if debounce == false then local player = Player:GetPlayerFromCharacter(hit.Parent) game:GetService("StarterGui").Animations.AnimationList.Animationcontroller.Disabled = false debounce = true end end function TouchEnded(hit) if debounce == true then local player = Player:GetPlayerFromCharacter(hit.Parent) game:GetService("StarterGui").Animations.AnimationList.Animationcontroller.Disabled = true debounce = false end end script.Parent.Touched:Connect(Touched) script.Parent.TouchEnded:Connect(TouchEnded)