Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Server to Client not working turns nil value?

Asked by 5 years ago
Edited 5 years ago

Hi I'm trying to make it so when "Experience" is changed it sends the value to the client of that changed exp. So in the client a text label might say "Experience: (value)" but when I do it, the client saids the value is nil even though it isn't.

-- OUTPUT ERRORS -- 16:27:39.791 - Unable to cast value to Object 16:27:39.792 - Stack Begin 16:27:39.793 - Script 'ServerScriptService.Script', Line 10

16:27:39.793 - Stack End

-- Server

local d = {
    level = 12,
    exp = 15,
    gold = 0
}

local createPopupRequest = game.ReplicatedStorage:WaitForChild("RemoteFunction")
local function onPlayerAdded(player)
    wait(1)
    createPopupRequest:InvokeClient(d.exp)
end

game.Players.PlayerAdded:Connect(onPlayerAdded)
-- Client




local createPopupRequest = game.ReplicatedStorage:WaitForChild("RemoteFunction")

local function onCreatePopupRequested(val) -- it doesn't return a player value a it doesn't need to.
    script.Parent.TextLabel.Text = "Gold = " .. val
end

createPopupRequest.OnClientInvoke = onCreatePopupRequested
0
mind you that the local function isn't commented on the actual script it is here for some reason Kaosinfusedknight 36 — 5y
0
i had the same thing but why don't you just return that value Is_Hunter 152 — 5y

1 answer

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago
-- Server

local d = {
    level = 12,
    exp = 15,
    gold = 0
}

local createPopupRequest = game.ReplicatedStorage:WaitForChild("RemoteFunction")
local function onPlayerAdded(player)
    wait(1)
    createPopupRequest:InvokeClient(player, d.exp)
end

game.Players.PlayerAdded:Connect(onPlayerAdded)

--Client


local createPopupRequest = game.ReplicatedStorage:WaitForChild("RemoteFunction")

local function onCreatePopupRequested(val) 
    script.Parent.TextLabel.Text = "Gold = " .. val
end

createPopupRequest.OnClientInvoke = onCreatePopupRequested

Let me know how that works. And you should change it to a RemoteEvent.

1
didnt work Kaosinfusedknight 36 — 5y
Ad

Answer this question