So, i have a fairly simple script. however, this small error keeps popping up and i have no idea why. The error is related to getting the player from character.
Code:
local debounce = true
script.Parent.Touched:Connect(function(otherpart)
if debounce == true then
local player = game.Players:GetPlayerFromCharacter(otherpart.Parent)
player:FindFirstChild("leaderstats").Stickers.Value += 1
script.Parent.yipee:Play()
debounce = false
script.Parent.Orientation = Vector3.new(script.Parent.Orientation.X,script.Parent.Orientation.Y,-90)
wait(1)
script.Parent:Destroy()
end
end)
When using the .Touched event, it is vital to remember that it will detect literally anything that touches the part; as mentioned, otherpart will return anything and this includes the baseplate. You need to add a check to make sure that whatever the part is touching, has a humanoid.
I have amended your code to account for this change.
local debounce = true
script.Parent.Touched:Connect(function(otherpart)
if debounce == true and otherpart.Parent:FindFirstChild("Humanoid") then
print("Player humanoid found!")
local player = game.Players:GetPlayerFromCharacter(otherpart.Parent)
player:FindFirstChild("leaderstats").Stickers.Value += 1
script.Parent.yipee:Play()
debounce = false
script.Parent.Orientation = Vector3.new(script.Parent.Orientation.X,script.Parent.Orientation.Y,-90)
wait(1)
script.Parent:Destroy()
end
end)