oBrodyz
(Brodster)
September 14, 2023, 1:45am
#1
I am trying to make a sell pad for my friends simulator game.
It is in workspace with a script inside the sellpart.
The sell pad does not work could someone please explain why.
local sellPart = script.Parent
sellPart.Touched:Connect(function(hit)
local leaderstats = hit.Parent:FindFirstChild("leaderstats")
local ingots = leaderstats:FindFirstChild("Ingots")
local cash = leaderstats:FindFirstChild("Cash")
cash.Value = cash.Value + ingots.Value
ingots.Value = 0
end)
any errors? did the touch event fire?
Angermode
(Angermode)
September 14, 2023, 1:50am
#3
Does it throw an error?
Have you checked if the hit object is actually a humanoid character and not some random object?
Have you checked if the leaderstats in the character / player exist?
oBrodyz
(Brodster)
September 14, 2023, 1:50am
#4
Yes,
Workspace.Sell.sellScript:5: attempt to index nil with 'FindFirstChild' - Server - sellScript:5
oBrodyz
(Brodster)
September 14, 2023, 1:51am
#5
Yes, I do get an error.
Workspace.Sell.sellScript:5: attempt to index nil with 'FindFirstChild' - Server - sellScript:5
XXXTMS
(tms)
September 14, 2023, 1:52am
#6
Leaderstats aren’t defined inside the character. I’m assuming you put them inside of the player for it to work.
local sellPart = script.Parent
sellPart.Touched:Connect(function(hit)
local leaderstats = game.Players[hit.Parent.Name]:FindFirstChild("leaderstats")
local ingots = leaderstats:FindFirstChild("Ingots")
local cash = leaderstats:FindFirstChild("Cash")
cash.Value = cash.Value + ingots.Value
ingots.Value = 0
end)
1 Like
XXXTMS
(tms)
September 14, 2023, 1:55am
#8
I’m pretty sure I understand that already. Leaderstats are never parented to the character.
oBrodyz
(Brodster)
September 14, 2023, 1:55am
#9
Thank you for letting me know that the leaderstats were not defined!
1 Like
Angermode
(Angermode)
September 14, 2023, 1:56am
#10
I know, I was providing it as reference for Brodster.
1 Like
XXXTMS
(tms)
September 14, 2023, 1:57am
#11
Oh! My apologiesssssssssssssssss.
system
(system)
Closed
September 28, 2023, 1:58am
#12
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.