snobW0lf
(Snoww)
October 6, 2020, 4:17am
#1
I have a script that works fine but there is an error that bugs me every time I touch the part can you help me with it?
script.Parent.Touched:Connect(function(hit)
local player = hit.Parent:FindFirstChild("Humanoid")
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
if plr.leaderstats["Pog Coins"].Value >= 0 then
wait ()
script.Disabled = true
script.Parent.Transparency = 1
script.Parent.CanCollide = false
plr.leaderstats["Pog Coins"].Value = plr.leaderstats["Pog Coins"].Value +2
wait (1)
script.Parent.Transparency = 0
script.Parent.CanCollide = true
script.Disabled = false
end
end)
Because you didnt filter what the part touches. Use if statement. Touch will return any part it touches
snobW0lf
(Snoww)
October 6, 2020, 4:20am
#3
but no objects are touching it and its floating above the ground
It appears that you have never created the leaderstats instance, as it errors as nil.
snobW0lf
(Snoww)
October 6, 2020, 4:22am
#5
I have created a leaderstats though, and the error only happens when I touch it
HonestJar
(HonestJar)
October 6, 2020, 4:23am
#6
Get rid of local player = hit.Parent:FindFirstChild(“Humanoid”) and replace it with if hit.Parent:FindFirstChild(“Humanoid”) then local plr = game.Players:GetPlayerFromCharacter(hit.Parent).
1 Like
Try putting a print(hit.Parent.Name) in the code and see what the name of the object that touches it is.
snobW0lf
(Snoww)
October 6, 2020, 4:25am
#8
It says its my character thats hitting it.
HonestJar
(HonestJar)
October 6, 2020, 4:26am
#9
Can you show us your leaderstats script?
Make sure that your leaderstats are inside your player when testing.
snobW0lf
(Snoww)
October 6, 2020, 4:26am
#11
thank you for all of your help it fixed the error
HonestJar
(HonestJar)
October 6, 2020, 4:27am
#12
Oh yea no problem. Glad I could help.
1 Like