Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How Do I Update a players leaderstats from a script?

Asked by 5 years ago
Edited 5 years ago

I'm Trying to check if the player is in a specific team and has a the value of X then they could use the button can anyone help

local CoinWorth = 50
Button.Touched:Connect(function(hit)

if hit.Parent:FindFirstChild("Humanoid") then

local Plr = workspace[hit.Parent.Name]

local Player = game.Players:GetPlayerFromCharacter(Plr)

if Player.Team == "Red" and Player.leaderstats.Coins.Value >= CoinWorth then

Player.leaderstats.Coins.Value = Player.leaderstats.Coins.Value - CoinWorth

end

end

end)

1 answer

Log in to vote
0
Answered by
JakyeRU 637 Moderation Voter
5 years ago

Hello. Here I fixed your Script and I added Debounce. ``` local CoinWorth = 50 local WaitTime = 5 local Debounce = false

function onHit(hit) if hit.Parent:FindFirstChild("Humanoid") then local PlayerCharacter = game.Workspace[hit.Parent.Name] local Player = game.Players:GetPlayerFromCharacter(PlayerCharacter) if Player.Team.Name == "Red" and Player.leaderstats.Coins.Value >= CoinWorth and Debounce == false then Debounce = true Player.leaderstats.Coins.Value = Player.leaderstats.Coins.Value - CoinWorth wait(WaitTime) Debounce = false end end end

script.Parent.Touched:Connect(onHit) You tried to check player's team by player.Team == "Red". This is like you are trying to check a team name like this. if game.Teams.Red == "Red"" then print("True") end ``` Which is incorrect. You can do: if player.Team.Name == "Red" or if player.Team == game.Teams.Red.

0
Thanks :) For The Help I'm just a bit noobie when it comes to creating the script i know how i want to approach the problem just don't know the most eficient way to do it EffilnuC 7 — 5y
0
No problem. Everyone was a beginner at a time. JakyeRU 637 — 5y
Ad

Answer this question