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

Cant Make A LeaderStat Value Change?

Asked by 4 years ago

Please encode Lua code in the Lua block code tag (look for the Lua icon in the editor).

I have made 3 leaderstats like this:

game.Players.PlayerAdded:Connect(function(Player) local Stats = Instance.new('Folder',Player) Stats.Name = 'leaderstats'

local Robux = Instance.new('IntValue',Stats)
Robux.Name = 'Robux' 
Robux.Value = 0  

local Amount = Instance.new('IntValue',Stats)
Amount.Name = 'Amount'
Amount.Value = 1

end)

the script is in ServerScriptService. I have made a GUI button with this local script:

local Player = game.Players.LocalPlayer local PlayerStats = Player:WaitForChild('leaderstats'):WaitForChild('Robux') local Amount = Player:WaitForChild('leaderstats'):WaitForChild('Amount')

script.Parent.MouseButton1Click:Connect(function() print("Clicked") PlayerStats.Value = PlayerStats.Value + Amount end)

I want to make so i can change how much players will get pr click like when you buy something in a shop.

Pls consider helpinh thx :)

0
Note: Select the part of the text that's your code and then click the lua button ( You can edit this question by clicking on the button right under the comments ) Leamir 3138 — 4y
0
But i want the value only to change at the Client not the Server AWE2007WE 0 — 4y

2 answers

Log in to vote
0
Answered by 4 years ago

You have to use Normal Script. With local scripts, you cant change values without remote controls.

0
Actually can, it will just not be replicated to others Leamir 3138 — 4y
Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

You just made some simple errors in your script.

Local script:

local Player = game.Players.LocalPlayer

local PlayerStats = Player:WaitForChild("leaderstats"):FindFirstChild("Robux")

local Amount = Player:WaitForChild("leaderstats"):FindFirstChild("Amount")

local RemoteEvent = ReplicatedStorage:WaitForChild("RemoteEvent")

script.Parent.MouseButton1Click:Connect(function() 

PlayerStats.Value = PlayerStats.Value + 1
Amount.Value = Amount.Value + 1

end)

If a player clicks the button, it increases both the values by 1 and other player's won't see the change since it's a local script and it doesn't get replicated to the server.

Answer this question