I need help with my XP check system

Hi! I’m King, I am trying to achieve an XP check system. I already have the XP minutes sytem. When a player runs “-xpcheck [user]”, it is supposed to check their minutes for the past 60 minutes. I have a boolvalue that shows the minutes they have. It removes one minute every hour, unless their value is already at 0! But, when I try to send a message to the client who ran the command, it gets an error in the local script! I’m trying to make it like Kavra’s Kingdom XP check, but I am having issues!

Picture of the error:


Picture of UI:
image
This is what is inside a player once they join.
image

Server Script Service Code:

game.Players.PlayerAdded:Connect(function(plr)
	plr.Chatted:Connect(function(msg)
		if plr:GetRankInGroup(7048567) >= 9 then
			local words = string.split(msg, " ")
			if words[1] == "-xpcheck" then
				local name = words[2]
				local player = game.Players:FindFirstChild(name)
				if player then
					game.ReplicatedStorage.XPCheck:FireClient(plr, player.Name, player.Minutes.Value)
					local ti = TweenInfo.new(0.5, Enum.EasingStyle.Linear)
					local frame = plr.PlayerGui.XPCheck.XPCheck:Clone()
					game:GetService("TweenService"):Create(frame, ti, { Position = UDim2.new(0.311, 0, 0.287, 0)}):Play()
					frame.Desc.Text = "In the last 60 minutes, "..player.Name.." has has earned "..player.Minutes.Value.." Minutes."
				end
			end
		end
	end)
end)

Local Script Code:

local ti = TweenInfo.new(0.5, Enum.EasingStyle.Linear)

game:GetService("TweenService"):Create(script.Parent, ti, { Position = UDim2.new(0.311, 0, 0.287, 0)}):Play()

game.ReplicatedStorage.XPCheck.OnClientEvent:Connect(function(plr, p, name, mins)
	script.Parent.Desc.Text = "In the past 60 minutes, "..name.." has earned "..mins.." Minutes worth of XP!"
	game:GetService("TweenService"):Create(script.Parent, ti, { Position = UDim2.new(0.311, 0, 0.287, 0)}):Play()
	game:GetService("StarterGui"):SetCore("ChatMakeSystemMessage", {
		Text = "XP Check: "..plr.Name.." XP Checked "..name.."! In the past 60 minutes, "..name.." has earned "..mins.." XP!",
		Color = Color3.new(0, 0.666667, 1),
		Font = Enum.Font.SourceSansBold,
		Size = Enum.FontSize.Size32,
	})
end)

I have added an extra variable called “P” and removed it too, so either way I still get this error.

Any help is appreciated!

These lines may be causing the problem. One or more of the values that you are concatenating with strings on this line are nil. Check name and mins. These two may be nil. Also, put these values inside of a tostring() when concatenating, unless the values are already strings.

Lines in the client’s script:

Text = "XP Check: "..plr.Name.." XP Checked "..name.."! In the past 60 minutes, "..name.." has earned "..mins.." XP!",
script.Parent.Desc.Text = "In the past 60 minutes, "..name.." has earned "..mins.." Minutes worth of XP!"
2 Likes

I believe the minutes and the name should be strings

1 Like

Ok so I re-wrote your code in my own experience to test what you have written and I have found the cause.

The issue is that the value “mins” your trying to concatenate is == to nil. The reason why this is because of what your sending over the remote event. You have added “plr” in the front value which is incorrect. If your looking to add the “name” then it should be at the front and remove the “plr” value your passing through.

I think your getting mixed up with how remote events work. When you fire from the client to the server (client → server) you get a parameter automatically given to you that is the player (the client that sent the request). This however is not the same when sending from server to client (server → client) where you do not get this paramater.

Example Local Script Code (works I tested it):

game.ReplicatedStorage.XPCheck.OnClientEvent:Connect(function(name, mins)
	script.Parent.Desc.Text = "In the past 60 minutes, "..name.." has earned "..mins.." Minutes worth of XP!"
	game:GetService("TweenService"):Create(script.Parent, ti, { Position = UDim2.new(0.311, 0, 0.287, 0)}):Play()
	game:GetService("StarterGui"):SetCore("ChatMakeSystemMessage", {
		Text = "XP Check: "..plr.Name.." XP Checked "..name.."! In the past 60 minutes, "..name.." has earned "..mins.." XP!",
		Color = Color3.new(0, 0.666667, 1),
		Font = Enum.Font.SourceSansBold,
		Size = Enum.FontSize.Size32,
	})
end)
1 Like

So on the server side would I keep “plr” at the beginning?

Correct. Roblox gives you a player parameter when firing from the client (I am guessing due to exploiters being able to fire the event it allows you to ensure you do the actions to the user who fired it; otherwise you would need to send the client from Player.LocalPlayer that an exploiter could fake).

1 Like

What would I do for the “plr” part of it since I have it in the chat message to announce to the entire server?

Just pass the player who sent the message as an extra parameter?
image

Um also why are you just firing to one client then if you want everyone to see it? Would you not just do :FireAllClients()?

Oooooh! Thank you! I will try that, I am still new to client to server server to client stuff.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.