Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

(SOLVED)Leaderstats changer not working in normal games, only in studio?

local plr = script.Parent.Parent.Parent.Parent.Parent.Parent

function click()
	plr.leaderstats.Clicks.Value = plr.leaderstats.Clicks.Value + 1
end

script.Parent.MouseButton1Click:connect(click)

It's in a GUI and I've already tried script and local script and it still would do nothing.

2 answers

✓ Accepted answer

Put everything in a local script and use a RemoteEvent inside of ReplicatedStorage, also you can get the player by just doing

local plr = game:GetService("Players").LocalPlayer
local rs = game:GetService("ReplicatedStorage")

function click()
    rs.ClickEvent:FireServer() -- Create a RemoteEvent in ReplicatedStorage and call it ClickEvent
end

script.Parent.MouseButton1Click:connect(click)

And on a server script inside of ServerScriptService would be

local rs = game:GetService("ReplicatedStorage")

rs.ClickEvent.OnServerEvent:connect(function(player) -- Remote events always return the player
	player.leaderstats.Clicks.Value = player.leaderstats.Clicks.Value + 1
end)

If you have any questions or if this does not work please let me know.

4 comments

0

Thanks! I will try that in a moment.

0

So just trying to being clear to myself, so now I do not put functions in local scripts and put them in ServerScriptService with a server script?

0

The functions can go in a local script, the server script can have the code I mentioned above.

0

So can I have many of these? And will FE affect my Developer Product script?

Im assuming your game is FE. If it is then in studio you can imagine playing the game and Server and Client are all together. Instead I reccomend doing Server testing which can be done from the same menu as test but it will say server, it will create new windows and you will be able to properly test your game out. You should also use Remote Events if that is a GUI. https://wiki.roblox.com/index.php?title=Remote_Functions_%26_Events

2 comments

0

Hi there, thanks. I've already tried doing that but it's still the same. I think it has to be something with FE?

0

Because I'm not familiar with Remove Events

This discussion is preserved as it was. New answers, comments, and votes are closed.