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

Server script not being cooperative and not printing player intvalue correctly? please help.

In a localscript i have a remote event that fires to the server, remote events automatically make the player the first parameter so the script on the servers side has the player. However, when i run these scripts below:

local lvlup = game:GetService("ReplicatedStorage"):WaitForChild("RE"):WaitForChild("lvlup")
local lvlupreturn = game:GetService("ReplicatedStorage"):WaitForChild("RE"):WaitForChild("lvlupreturn")

local player = game.Players.LocalPlayer
local leaderboard = player:WaitForChild("leaderboard")
local XP = leaderboard.XP
local Lvl = leaderboard.Lvl
local XPreq = Lvl.Value*100

local function set()
value.Text = XP.Value .. " / " .. XPreq
script.Parent.Size = UDim2.new(XP.Value/XPreq,0,1,0)
end

local player = game.Players.LocalPlayer
local leaderboard = player:WaitForChild("leaderboard")
local XP = leaderboard.XP

local debounce = true

local function levelup()
    if debounce == true then
        debounce = false
        lvlup:FireServer()
        end
        lvlupreturn.OnClientEvent:Connect(function()
        set()
        debounce = true
    end)
end

XP:GetPropertyChangedSignal("Value"):Connect(function()
    levelup()
end)

Server

local lvlup = game:GetService("ReplicatedStorage"):WaitForChild("RE"):WaitForChild("lvlup")
local lvlupreturn = game:GetService("ReplicatedStorage"):WaitForChild("RE"):WaitForChild("lvlupreturn")

lvlup.OnServerEvent:Connect(function(player)
local XP = player.leaderboard.XP
print(XP.Value)
lvlupreturn:FireClient(player)
end)

The server script always prints XP.Value as 0 even when it isnt

2 comments

0

it appears that there is no change occuring to the XP variable from scripts, is there some other way you are modifying it?

0

i changed it by going to the intvalue manually and changing it

1 answer

✓ Accepted answer

"i changed it by going to the intvalue manually and changing it"

If you test play solo in Roblox Studio, Roblox is simulating both the server and client - you start out seeing thing as the client, so changing the XP's value will be filtered -- the server won't see it. Click on the Client/Server toggle before making your changes and they will be properly replicated.

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