My leaderstats script:
game.Players.PlayerAdded:Connect(function(Player) local Stats = Instance.new("Folder",Player) Stats.Name = "leaderstats" local DiceRolls = Instance.new("IntValue",Stats) DiceRolls.Name = "Dice Roll's" DiceRolls.Value = 0 end)
Is it simple, I will make for you a FE for prevent hacking!
First you need to make a Remote Event in ReplicatedStorage
Now Insert a Local Script in the ImageButton and enter the code below :
local debounce = false script.Parent.MouseButton1Click:Connect(function() if not debounce then debounce = true game.ReplicatedStorage.RemoteEvent:FireServer() wait(1) debounce = false end end)
Now insert a Script in Server Script Service and type this below:
game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(plr) plr.leaderstats.Points.Value = plr.leaderstats.Points.Value + 1 -- Change points to your currency! end)
Try this, if any issue , reply me!
Alright like @OriginalDevelops said, you need a RemoteEvent to let ServerScript and LocalScript communicate.
Therefore, you need to put a RemoteEvent in ReplicatedStorage since the LocalScript cannot access ServerStorage.
In LocalScript (This LocalScript should be placed into the ImageButton):
local Clicked = false -- This is a "debounce". I wrote "Clicked" to avoid confusion. local RemoteEvent = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent") script.Parent.MouseButton1Click:Connect(function() if Clicked == false then Clicked = true RemoteEvent:FireServer() wait(1) Clicked = false end end)
In ServerScript (You can use your original ServerScript in the question you asked):
local RemoteEvent = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent") game.Players.PlayerAdded:Connect(function(Player) local Stats = Instance.new("Folder",Player) Stats.Name = "leaderstats" local DiceRolls = Instance.new("IntValue",Stats) DiceRolls.Name = "Dice Roll's" DiceRolls.Value = 0 local Cash = Instance.new("IntValue", Stats) -- Creating a new Cash value in leaderstats Cash.Name = "Cash" Cash.Value = 0 while wait() do -- Im using while loop here so that the function can be used several times instead of 1 time. RemoteEvent.OnServerEvent:Connect(function(Player) Player.Stats.Cash.Value = Player.Stats.Cash.Value + 1 end) end end)
I have fixed it! All i did was watch this youtube video: https://www.youtube.com/watch?v=FZH8kXC4V2o
My script now:
local Player = game.Players.LocalPlayer local PlayerStats = Player:WaitForChild('leaderstats'):WaitForChild('Dice Rolls') script.Parent.MouseButton1Click:Connect(function() PlayerStats.Value = PlayerStats.Value + 1 end)
Closed as Not Constructive by youtubemasterWOW
This question has been closed because it is not constructive to others or the asker. Most commonly, questions that are requests with no attempt from the asker to solve their problem will fall into this category.
Why was this question closed?