How to reset a certain player stats by typing their name in a text box
Well you would need to use remote events to replicate it over onto the server and you would need to pass over the text inside of the text box. After that, you would need to check if it can find the player in server (if you just want it to run the command on a player in the current server), then you would need to set the stat value to nil.
well i have no idea how to do that
can you send a pic or something
I think an easier and more secure way would be to use a chat command such as :resetstats plr or something like that, it also wouldn’t take as much scripting.
game.Players.PlayerAdded:Connect(function(player)
player.Chatted:Connect(function(msg)
if player.UserId == userId then --Paste in your user ID where it says 'userId'
if msg:sub(1,11) == ":resetstats" then --Change the command to whatever you want
if game.Players:FindFirstChild(msg:sub(13)) then
game.Players:FindFirstChild(msg:sub(13)).leaderstats.Stat.Value = 0 --Change 'Stat' to the stat name.
end
end
end
end)
end)
i would like for it to be in a gui
If you use any of them, make sure to make it a Script
If you want it to be a command then use this:
local textbox = script.Parent
textbox.FocusLost:Connect(function()
local text = textbox.Text
if text:sub(1,11) == ":resetstats" then --Change the command to whatever you want
if game.Players:FindFirstChild(text:sub(13)) then
game.Players:FindFirstChild(text:sub(13)).leaderstats.Stat.Value = 0 --Change 'Stat' to the stat name.
end
end
end)
Otherwise, use this:
local textbox = script.Parent
textbox.FocusLost:Connect(function()
local text = textbox.Text
if game.Players:FindFirstChild(text) then
game.Players:FindFirstChild(text).leaderstats.Stat.Value = 0 --Change 'Stat' to the stat name.
end
end)
but i want to make it in a gui
Like when you click a button???
yes, when you type a name in the player u select confirm and it resets the players stats the u selected
You would need to use RemoteEvents to achieve that.
i know but how you do it
1. Make a LocalScript inside the text button
local textbox = script.Parent -- Change to wherever the textbox is
script.Parent.MouseButton1Down:Connect(function()
local text = textbox.Text
if game.Players:FindFirstChild(text) then
game.ReplicatedStorage.RemoteEvent:FireServer(game.Players.LocalPlayer,game.Players:FindFirstChild(text))
end
end)
- Make a RemoteEvent in ReplicatedStorage
3. Make a Server Script in ServerScriptService
game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(LocalPlayer,playerToSeek)
playerToSeek.leaderstats.Stat.Value = 0 --Change 'Stat' to the stat name.
end)
okay it would be something like
local:
local RemoteEvent = game:GetService("RepliatedStorage"):WaitForChild("RemoteEvent")
textbox.FocusLost:Connect(function()
local text = textbox.text
local playerToFind = game.Players:FindFirstChild(textbox.text)
if playerToFind then
print("Found")
RemoteEvent:FireServer(localPlayer, playerToFind)
end)
Server:
local RemoteEvent = game:GetService("RepliatedStorage"):WaitForChild("RemoteEvent")
RemoteEvent.OnServerEvent:Connect(function(localPlayer, playerToFind)
playerToFind.leaderstats.Cash.Value = 0
print(localPlayer.." reset "..playerToFind.."'s stats!")
the part that says
local text = textbox.Text
would it be calling the text box’s text (the players name)
i am just trying to make sure i have everything right
Yes, you would have to make a TextBox and define its text
ok thank you
Have fun building your game!⠀⠀⠀⠀⠀⠀⠀⠀⠀
thank youuu