this is the script
script.Parent.Touched:Connect(function(hit) local Player = game.Players:GetPlayerFromCharacter(hit.parent) if Player:WaitForChild("leaderstats"):WaitForChild("Potatoes").Value == 6 then local Player = game.Players.GetPlayerFromCharacter(hit.Parent) Player.leaderstats.Cash.Value = Player.leaderstats.Cash.Value + 10 end end)
i don't get any errors but somethings not right because the cash value isn't going up
Please use a code block next time.
You should check first look for the Touched
event on the part.
local Part = workspace.PartNameHere; Part.Touched:Connect(function(Hit) end)
Hit is the part that touched the part, eg the Left Arm, or Right Leg etc.
We need to check if Hit is a descendant of the Player's Character
, we can do this in many ways.
local Part = workspace.PartNameHere; Part.Touched:Connect(function(Hit) local Player = game.Players:GetPlayerFromCharacter(Hit.Parent); if Player then local Value = Player.leaderstats.Potatoes; if Value.Value >= 6 then Value.Parent.Cash.Value += 10; -- This will add 10 on. end end end)
If it was, then the Player will be a player, otherwise it will be nil, thats why we check.
Please use the code block next time, it's the 6th button.
I currently have no idea why Zethusimam's code didn't work, so I'll rewrite it.
(By the way, please, next time give us more information instead of just throwing us the code expecting us to know exactly what your problem is.)
Anyways, here's what I believe what you did wrong: You probably have more than 6 Potatoes and/or a non-player touched it causing it the error. Try this:
script.Parent.Touched:Connect( function(hit) local Player = game.Players:GetPlayerFromCharacter(hit.parent) if Player then -- detecting if player if Player:WaitForChild("leaderstats"):WaitForChild("Potatoes").Value >= 6 then -- if 6 or more local Player = game.Players.GetPlayerFromCharacter(hit.Parent) Player.leaderstats.Cash.Value = Player.leaderstats.Cash.Value + 10 end end end )
Closed as Not Constructive by EzraNehemiah_TF2
This question has been closed because it is not constructive to others or the asker. Most commonly, questions that are requests with no attempt from the asker to solve their problem will fall into this category.
Why was this question closed?