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

Server to Client not working turns nil value?

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

2 comments

0

mind you that the local function isn't commented on the actual script it is here for some reason

0

i had the same thing but why don't you just return that value

1 answer

-- 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 comment

1

didnt work

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