Basically, I need a script for a tool that opens a GUI locally then ads coins to the leader stats but there was an error that had an issue when line 13. Also, this is the script for the remote. Please help me thanks:
01 | local repStorage = game:GetService( "ReplicatedStorage" ) |
02 | local remote = repStorage:WaitForChild( "Remote" ) |
03 |
04 | remote.OnServerEvent:connect( function (player) |
05 | local player = game.Players.LocalPlayer |
06 | local gui = game.Workspace.PlusOne |
07 | local Clicked = false |
08 |
09 | gui.Parent = nil |
10 |
11 | wait( 1 ) |
12 | local Clicked = true |
13 | gui.Parent = player.PlayerGui -- The error said it was comeing from this line! |
14 | wait(. 8 ) |
15 | game.Players.LocalPlayer.leaderstats.Coins.Value = game.Players.LocalPlayer.leaderstats.Coins.Value + 1 |
It is because you tried to redefine 'player' as if it were in a local script, you don't need to redefine player once you get it from an OnServerEvent, here's a refixed result:
01 | local repStorage = game:GetService( "ReplicatedStorage" ) |
02 | local remote = repStorage:WaitForChild( "Remote" ) |
03 |
04 | remote.OnServerEvent:connect( function (player) |
05 | local gui = game.Workspace.PlusOne |
06 | local Clicked = false |
07 |
08 | gui.Parent = nil |
09 |
10 | wait( 1 ) |
11 | local Clicked = true |
12 | gui.Parent = player.PlayerGui |
13 | wait(. 8 ) |
14 | game.Players.LocalPlayer.leaderstats.Coins.Value = game.Players.LocalPlayer.leaderstats.Coins.Value + 1 |
15 | gui.Parent = nil |
16 | Clicked = false |
17 | while true do wait() |
18 |
19 | end |
20 | end ) |
This should be in a Local Script in the tool. Also move ur gui into the StarterGui and set it to disabled
1 | local gui = game.StarterGui.PlusOne |
2 | script.Parent.MouseButton 1 Click:Connect( function (plr) |
3 | local leaderstats = plr:WaitForChild( "leaderstats" ) if leaderstats then |
4 | local cash = leaderstats:FindFirstChild( "Cash" ) if cash then |
5 | gui.Enabled = true |
6 | cash.Value = cash.Value + 1 |
7 | end |
8 | end |
9 | end ) |
There. Way shorter and it should work. If it doesnt work then comment and i'll see for any problems.