Adding Points System

I am trying to add points with a GUI, here is my current code:

Server Script:

local DSService = game:GetService("DataStoreService")
local DS = DSService:GetDataStore("DataStore1")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage:WaitForChild("Points")

game.Players.PlayerAdded:Connect(function(player)
	local Leaderstats = Instance.new("Folder", player)
	Leaderstats.Name = "leaderstats"

	local Points = Instance.new("IntValue", Leaderstats)
	Points.Name = "Points"
	
	local Data = DS:GetAsync(player.UserId)
	
	if Data then
		Points.Value = Data
	end
end)

game.Players.PlayerRemoving:Connect(function(player)
	DS:SetAsync(player.UserId, player.leaderstats.Points.Value)
end)

function confirm2(user, points)
	game.Players[user].leaderstats.Points.Value = game.Players[user].leaderstats.Points.Value + tonumber(points)
end

remoteEvent.OnServerEvent:Connect(confirm2)

Local Script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage:WaitForChild("Points")

function confirm()
	local user = script.Parent.Parent.username.Text
	local points = script.Parent.Parent.points.Text
	
	print(user)
	print(points)
	
	remoteEvent:FireServer(user, points)
end

script.Parent.MouseButton1Click:Connect(confirm)

In the local script, points and user is getting printed as 13 and Aka_Ethan110 (this is what I put into the GUI), however when I print points and user in the server script, I am getting Aka_Ethan110 for both points and user. Does anyone know why?

No, we don’t know why because you haven’t displayed anything where the text is set to the points or the user.

Could you explain more about what you mean?

You don’t make the text of any of those textlabels to the points value or the user value. So the reason is probably because of that, or if you have another script that does that please show.

image

You mean this?

Yes where’s the script that sets those texts to the points/user? It would look something like this;

user.Text = ???
points.Text = ???

That’s a variable that grabs the already set text of ‘username’ and ‘points’ it’s not the script that gives the labels each value.

1 Like

Try to add a player variable at the function and print it so you can check if it works like this:

function confirm2(player, user, points)
	print(player.Name)
	game.Players[user].leaderstats.Points.Value += points
end

and to fire the event use this:

local player = game.Players.LocalPlayer

remoteEvent:FireServer(player, user, points)
2 Likes

ServerScriptService.Script:26: invalid argument #2 (string expected, got Instance)

game.Players[user].leaderstats.Points.Value = game.Players[user].leaderstats.Points.Value + tonumber(points)

1 Like

That’s because the way your passing your arguments are incorrect.

When calling FireServer, the player argument is always passed, so you don’t need it there. Furthermore, your arguments are swapped around on the server.

Should be something like:
remoteEvent:FireServer(points, user)

function confirm2(player, points, user)

3 Likes

Thank you! You’ve helped me a lot!