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

How can I keep my warnings to stay when the player resets?

How can I make it so when the player resets, the warnings stay above their head and the Value remains the same?

local GroupId = 6998516 --REPLACE 1234567 WITH YOUR GROUP ID
local MinimumRankToUseCommand = 249 --REPLACE 255 WITH THE MINIMUM RANK ID TO USE THE !WARN COMMAND

game.Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		local WarningGUI = script.WarningGUI:Clone()
		WarningGUI.Parent = Character.Head
	end)
	
	Player.Chatted:Connect(function(Message)
		local SplitMessage = Message:split(" ")
		if SplitMessage[1] == "!warn" and Player:GetRankInGroup(GroupId) >= MinimumRankToUseCommand then
			local NameOfPlayerToWarn = SplitMessage[2]
			local PlayerToWarn = game.Players:FindFirstChild(NameOfPlayerToWarn)
			local Reason = Message:split(NameOfPlayerToWarn)[2]
			
			local WarningGUI = PlayerToWarn.Character.Head.WarningGUI
			local CurrentWarnings = WarningGUI.Warnings
			
			CurrentWarnings.Value = CurrentWarnings.Value + 1
			WarningGUI.WarningLabel.Text = "W" .. CurrentWarnings.Value .. " - " .. Reason
			
			if CurrentWarnings.Value >= 3 then
				PlayerToWarn:Kick("You've reached the maximum number of warnings. If this was a result of staff abuse please message us immediately with evidence.")
			end
		end
	end)
end)

3 answers

This is just an idea I randomly thought in my head. There's a folder called "PlayerWarnData" in the workspace, serverstorage, etc. When a player joins, a numbervalue is added to the folder with the name of the player's username. So when a player gets warned, you'd add one warning to the player's numbervalue. They won't be able to reset it by resetting.

Again, it's just an idea that I thought in like 5 seconds. Hopefully that might give you an idea on what to do

1 comment

0

It sounds like a good idea, but I'd have no idea on how to do that.

Try this: (Note: Might have few errors in the new code but it Should work, as im not in front of my computer at the moment!): (Note2: Depending if ServerStorage is available you may need to find a new place for the new folder system.

Anyway the new code:

local GroupId = 6998516 --REPLACE 1234567 WITH YOUR GROUP ID
local MinimumRankToUseCommand = 249 --REPLACE 255 WITH THE MINIMUM RANK ID TO USE THE !WARN COMMAND

--[[ 
###################################
# New Code! #######################
###################################
 ]]
local PlayerStatsFolderName = "Player Warnings" -- Replace this to what your warnings folder will be named (Optional!)

--// Don't change this, This simply creates a folder in ServerStorage so we can store players warnings
local PlayerStats = (function() 
	local SS = game:GetService("ServerStorage")	
	local F = SS:FindFirstChild(PlayerStatsFolderName) ~= nil and SS[PlayerStatsFolderName] or (function() 
		local F = Instance.new("Folder",SS) 
		F.Name = PlayerStatsFolderName 
		return F 
	end)() 
	return F 
end)()


function ADDPlayer(Player)
	local Name = Player.Name
	local PlayerST = PlayerStats:FindFirstChild(Name)
	if(PlayerST == nil) then
		PlayerST = Instance.new("Folder",PlayerStats)
		PlayerST.Name = Name
	end
	local Warn = PlayerST:FindFirstChild("CurrentWarnings")
	if(Warn == nil) then
		Warn = Instance.new("IntValue",PlayerST)
		Warn.Name = "CurrentWarnings"
	end
	return PlayerST
end



game.Players.PlayerAdded:Connect(function(Player)
    Player.CharacterAdded:Connect(function(Character)
		ADDPlayer(Player) --// Add this player to our system Note: not using the return from this function....
        local WarningGUI = script.WarningGUI:Clone()
        WarningGUI.Parent = Character.Head
    end)

    Player.Chatted:Connect(function(Message)
        local SplitMessage = Message:split(" ")
		local Name = Player.Name
        if SplitMessage[1] == "!warn" and Player:GetRankInGroup(GroupId) >= MinimumRankToUseCommand then
            local NameOfPlayerToWarn = SplitMessage[2]
            local PlayerToWarn = game.Players:FindFirstChild(NameOfPlayerToWarn)
            local Reason = Message:split(NameOfPlayerToWarn)[2]
			--// if player Joined normally with out changing their name this will find it otherwise it will create a folder for them!
			local PlayerHookup = PlayerStats:FindFirstChild("Name") or ADDPlayer(Player)
			local CurrentWarnings = PlayerHookup:FindFirstChild("CurrentWarnings")
			--// should never be called unless this player has a folder named after them but no stats.... WEIRD!
			if(CurrentWarnings == nil) then 
				warn("Warning!: Player named "..Name.." Has a malformed folder! \n Fixing Error....") 
				PlayerHookup = ADDPlayer(Player) 
				CurrentWarnings = PlayerHookup:["CurrentWarnings"]
			end
			
			
			local WarningGUI = PlayerToWarn.Character.Head.WarningGUI
			--  local CurrentWarnings = WarningGUI.Warnings
			CurrentWarnings.Value = CurrentWarnings.Value + 1
			
            WarningGUI.WarningLabel.Text = "W" .. CurrentWarnings.Value .. " - " .. Reason

            if CurrentWarnings.Value >= 3 then
                PlayerToWarn:Kick("You've reached the maximum number of warnings. If this was a result of staff abuse please message us immediately with evidence.")
            end
        end
    end)
end)

Let me know if theres any errors and ill see if i can correct them!

3 comments

0

This looks great, thank you for taking a huge portion of your time to right it, but I'm confused when you say "Folder", I know what they are, but where should I put it, what should I put in it?

0

just put the folder inside server storage. Sorry for the really late response, just remebered i left this lol. just encase that doesnt work try putting the folder in the workspace and change the line local SS = game:GetService("ServerStorage") to local SS = workspace. Hope this helps

0

wait a min i forgot i made it make the folder for you. But there is a check to see if that folder allready exists so it should be good! The script just makes the folder inside the object you change SS varable to

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