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)
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)
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)
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
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
wait()
script.Parent.MouseButton1Click:connect(
function()
local player = script.Parent.Parent.TextBox.Text
if player then
game.ReplicatedStorage.GiveWin:FireServer(player)
end
end)
wait()
script.Parent.MouseButton1Click:connect(
function()
local player = script.Parent.Parent.TextBox.Text
if player then
game.ReplicatedStorage.GiveWin:FireServer(player)
end
end)
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)
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.)