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?
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.
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)