I am working on a project and when a person touches the trigger the script is supposed to transfer the "squeaks" - leaderstat value to the "coins" -leaderstat value. I have listed my script below:
script.Parent.Touched:Connect(function(hit) local plr = game.Players:GetPlayerFromCharacter(hit.Parent) if plr then plr.leaderstats.Coins = plr.leaderstats.Coins.Value + plr.leaderstats.Sqeaks.Value plr.leaderstats.Sqeaks.Value = 0 end end)
You might need to check if the touch even had a player inside it in the first place. Also doing this I think would make the if plr useless so I just removed it. Also it says plr.leaderstats.Coins but no .value so I changed that also. So here:
script.Parent.Touched:Connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") then local plr = game.Players:GetPlayerFromCharacter(hit.Parent) plr.leaderstats.Coins.Value = plr.leaderstats.Coins.Value + plr.leaderstats.Sqeaks.Value plr.leaderstats.Sqeaks.Value = 0 end end end)
Oh there's a error. at line 5, you chnaged the coins, and not the coin's value. Change top this:
script.Parent.Touched:Connect(function(hit) local plr = game.Players:GetPlayerFromCharacter(hit.Parent) if plr then plr.leaderstats.Coins.Value = plr.leaderstats.Coins.Value + plr.leaderstats.Sqeaks.Value plr.leaderstats.Sqeaks.Value = 0 end end)
Also, make sure to put this in a script an not a local script!
Hope this helped!