Why is this cash giving script not working?

I made a gui for admins that you type in the player’s name and press the confirm button and a win is added to their leaderstat, but the output it saying im trying to index nil with wins (The stat nane)

Script:

wait()
script.Parent.MouseButton1Click:connect(
	function()
	local player = script.Parent.Parent.TextBox.Text
	if player then
		local wins = player.leaderstats.Wins.Value
		wins = wins + 1
	end
end)
1 Like

Make sure you understand client-server model.

other than that, “player” in the given script is a string.

2 Likes

Did you make it so it fires a remote event

1 Like

no but ill try that…

1 Like

The wait() is unnecessary, and ‘connect’ is not the proper one, its ‘Connect’. Keep in mind I’m not trying to be rude, just want you to know for next time

maybe try this?

local player = game.Players.LocalPlayer
 script.Parent.MouseButton1Click:connect(function()
	local text =  script.Parent.Parent.TextBox.Text
	if text then
       game.ReplicatedStorage.Remote:FireServer(player)
	end
end)

-- serverscript
game.ReplicatedStorage.Remte.OnServerEvent:Connect(function(player)
   local wins = player.leaderstats.Wins.Value
    wins = wins +1
end)
1 Like

You can’t give players the cash because of Roblox’s Filtering Enabled without firing remote events. What you gotta do is make it so the gui button is a fireserver one as a local script, and the server script is the one that does the server event (which gives the cash)

2 Likes

Ripperoni made a perfect video for what you’re trying to do, you could use his video to help with what you’re trying to do to make it so your cash giving gui is FE compatible

2 Likes

@WBostonW just try my script (30 charssss)

1 Like

yours doesnt work sorry!

–30 char

1 Like

There are 2 possible reasons for that:

1- You are using wins as variable for the value of wins, So it wont set the value of wins to anything else.

2- If its in a local script then it wont update the value of your wins unless you fire to the server to update.

To solve this I would do:

local wins = player.leaderstats.Wins
wins.Value = wins.Value + 1

(In case you didn’t understand what I meant in the 1st reason)

player.leaderstats.Wins.Value is the AMMOUNT of wins, When you do a variable for that then lets do this example:

local wins = player.leaderstats.Wins.Value
print(wins) -- If you have 2 Wins then it will print 2
wins = wins + 1
print(player.leaderstats.Wins.Value) -- Will print 2
print(wins) -- Will print 3
1 Like

Ight heres the scripts now:

Server:

game.ReplicatedStorage.GiveWin.OnServerEvent:Connect(function(player)
	player.leaderstats.Wins = player.leaderstats.Wins + 1
end)

GUI:

wait()
script.Parent.MouseButton1Click:connect(
	function()
	local player = script.Parent.Parent.TextBox.Text
	if player then
		game.ReplicatedStorage.GiveWin:FireServer(player)
	end
end)
1 Like

Like I said before, use ‘Connect’ instead of ‘connect’

1 Like

try this:

Server:

game.ReplicatedStorage.GiveWin.OnServerEvent:Connect(function(player, var)
	game.Players:FindFirstChild(var).leaderstats.Wins.Value += 1
end)

GUI:

wait()
script.Parent.MouseButton1Click:connect(
	function()
	local player = script.Parent.Parent.TextBox.Text
	if player then
		game.ReplicatedStorage.GiveWin:FireServer(player)
	end
end)
1 Like

You did player.leaderstats.Wins = player.leaderstats.Wins + 1

You shouldve done:

player.leaderstats.Wins.Value = player.leaderstats.Wins.Value + 1
-- (This way is shorter but does the same thing)
player.leaderstats.Wins.Value += 1
1 Like
local player = game.Players.LocalPlayer
 script.Parent.MouseButton1Click:connect(function()
	local text =  script.Parent.Parent.TextBox.Text
	if text then
       game.ReplicatedStorage.Remote:FireServer(player)
	end
end)

-- serverscript
game.ReplicatedStorage.Remte.OnServerEvent:Connect(function(player)
   local wins = player.leaderstats.Wins
    wins.Value = wins.Value +1
end)

Please tell me if I did something wrong

Server:

game.ReplicatedStorage.GiveWin.OnServerEvent:Connect(function(player, var)
	game.Players:FindFirstChild(var).leaderstats.Wins.Value += 1
end)

GUI:

wait()
script.Parent.MouseButton1Click:connect(
	function()
	local player = script.Parent.Parent.TextBox.Text
	if player then
		game.ReplicatedStorage.GiveWin:FireServer(player)
	end
end)

(Its the same code as @Latelyz but I fixed a thing in it.)

1 Like

You are adding a win to the person who fires the event.

It works! all i had to do was add the value thing! Thank you!

1 Like

Mark who ever solved your problem as the solution :slightly_smiling_face:

1 Like