game.Workspace.DustyDunes.Badges.Desert1.PrimaryPart.Touched:Connect(function(pot)
local hum = pot.Parent:FindFirstChild("Humanoid")
Character.Humanoid.WalkSpeed = 0
if hum == Character.Humanoid and detect == 0 then
detect = 1
print("Badge Gained!")
process("Floating On The Sand", 10, 20, game.Workspace.DustyDunes.Cameras.Desert1.CFrame)
end
end)
This code works completely fine if the player has not died at all since opening the client (or in my case, during playtesting). Otherwise, it will not run at all. The humanoidâs walkspeed is not altered, âBadge Gainedâ is not printed, and the process function is not executed. However, I do not get an error in the Output section.
Is this something to do with the Character being reset, or is it something else Iâm overlooking? This is a local script located in StarterPlayerScripts.
Hello Dave,
From a first glance your issue is most likely that the Character var is not being updated after you respawn.
If we could see the entire script thatâd be tremendously helpful, may I also ask what kind of script this is and itâs location as getting as much information as we can means we can help diagnose the issue more effectively and quickly.
You shouldnât define Character before the touched event, rather something like this
local Part = game.Workspace.DustyDunes.Badges.Desert1.PrimaryPart
Part.Touched:Connect(function(pot)
local Character
if pot.Parent:FindFirstChild("Humanoid") then
Character = Pot.Parent
local hum = pot.Parent:FindFirstChild("Humanoid")
Character.Humanoid.WalkSpeed = 0
if hum == Character.Humanoid and detect == 0 then
detect = 1
print("Badge Gained!")
process("Floating On The Sand", 10, 20, game.Workspace.DustyDunes.Cameras.Desert1.CFrame)
end
end
end)
Sorry for indents.
Like @realhigbead was saying and @RainScripts showed, make sure that your script can tell what the character is when it spawns, having it before the touched event doesnât signify âCharacterâ correctly.
Thank you very much for the code, it works consistently now.
The reason I was initially uncertain that the Character was the problem is because it isnât directly involved with the firing of the event. I definitely should have seen that it was part of everything inside the event.