local part = script.Parent
local playersService = game:GetService(“Players”)
part.Touched:Connect(function(partTouched)
if partTouched.Parent:FindFirstChild("Humanoid") then
if playersService:GetPlayerFromCharacter(partTouched.Parent) then
-- when the part is touched script here
end
end
end)
I need it so when touched a part my leaderstats go up 1 via a gui
Something like this if you are have another script to create leaderstats in the player. If not you can do the same thing just create a object to store the value in each player
local player = playersService:GetPlayerFromCharacter(partTouched.Parent)
if player then
-- when the part is touched script here
player.leaderstats.Coins.Value += 1
end
--In your client gui script
player.leaderstats.Coins.Changed:Connect(function(value)
yourTextLabel.Text = value
end)
I dont really want leaderstats im more focused on getting the gui to work. Would i pu that scrip in server script service along with the other script? Also the object i want the user is “CoinGiver” as a name so where would i change it so it would work.?
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
Do i put that instead of the other scripts. Would i put that script in server script service along with the other script? Also the object i want the user is “CoinGiver” as a name so where would i change it so it would work.?
The following code should work
This one is a normal script on the part
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)
if the script above doesnt work, insert the script in a normal script and change
local player = game.Players.LocalPlayer
to
local player = script:FindFirstAncestorOfClass("Player")