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

How can I make an ImageButton give me + 1 cash on my leaderstats? [closed]

Asked by
iVmk3 -143
4 years ago

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)

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?

3 answers

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

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!

0
This doesn't seem to add 1 to my leader stats. Every single script i have tried hasn't either. I can let you help me in Roblox Studio if you would like. iVmk3 -143 — 4y
0
You have to friend me in Roblox though iVmk3 -143 — 4y
0
Send me, I will accpect and solve for you when I’m break! OriginalDevelops 22 — 4y
0
Thank you! iVmk3 -143 — 4y
Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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)
0
Do I put the last script as my leaderstats script , or do I make this script the script I have for OriginalDevelops last script? iVmk3 -143 — 4y
0
your leaderstats script guest_20I8 266 — 4y
0
Ok. iVmk3 -143 — 4y
0
Now there are no leaderstats at all so I can't determine if this will work or not. iVmk3 -143 — 4y
View all comments (2 more)
0
No leaderstats? You need to add the RemoteEvent to ReplicatedStorage before you test the game or else the leaderstats won't appear guest_20I8 266 — 4y
0
They still dont iVmk3 -143 — 4y
Log in to vote
0
Answered by
iVmk3 -143
4 years ago

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)