local playersService = game:GetService("Players")
script.Parent.Touched:Connect(function(partTouched)
if partTouched.Parent:FindFirstChild("Humanoid") then
local player = playersService:GetPlayerFromCharacter(partTouched.Parent)
if player then
player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 1
script.Parent:Destroy()
end
end
end)
this one is inside the coin text as a local script
local player = game.Players.LocalPlayer
player.leaderstats.Coins:GetPropertyChangedSignal("Value"):Connect(function()
script.Parent.Text = player.leaderstats.Coins.Value
end)
It appears to me that at the end of your server script it destroys itâs parent, which is named âcoinsâ as showed in the output. If Iâm incorrect please inform me.
Edit: Wrote this in a rush, it appears I am incorrect. Unfortunately a fix cannot be found because there is not enough context shown quite yet in this topic. Could we take a look at the leaderstats instance inside of the player?
The error message is saying that leaderstats is an IntValue. Leaderstats should be a folder with an intvalue named Coins inside of it. Can I see the script where you add the playerâs leaderstats?
I have just looked in workspace i type up leaderstats and all i see is this
Just a heads up this wasnt by me, i had another 1 but its was wrong so this guy said this one would work, so i have just gone from here to be fair.
If you press ctrl+F in studio there will be a pop up menu to find lines of code in scripts, what I would recommend to find there is instance.new function
My first post was incorrect and it seems that the server script destroying itâs parent is not the issue here. The output screenshot you posted at the beginning is telling me that there is an instance named âleaderstatsâ inside of game.Players.LocalPlayer, and the screenshots you posted shows the server and local scripts inside of a ScreenGuiâs descendants, which, if the ScreenGui is inside of StarterGui, would be directly inside of game.Players.LocalPlayer.PlayerGui once the game runs.
local players = game:GetService("Players")
local debounce = false
local part = script.Parent
part.Touched:Connect(function(hit)
if debounce ~= true then
debounce = true
local character = hit.Parent
local humanoid = character:FindFirstChildWhichIsA("Humanoid")
if typeof(humanoid) == 'Instance' and humanoid:IsA("Humanoid") and humanoid.Health <= 0 then
return
end
local player
if typeof(character) == 'Instance' then
player = players:GetPlayerFromCharacter(character)
end
if typeof(player) == 'Instance' and player:IsA("Player") then
(player:WaitForChild("leaderstats"):WaitForChild("Coins") :: IntValue).Value += 1 -- luau be like 'InVaLiD tYpE' and so i went 'hush'
part:Destroy()
end
end
end)
Another edit: The reason your code isnât working is because Coins isnât a valid member of leaderstats, make sure you use WaitForChild if that isnât the case. The game may still need time to load.