I want to call a player value table but it won’t work for some reason…
This is the local script that calls it
boughtRequest = game.ReplicatedStorage:WaitForChild("BoughtRequest")
local gunInfo = require(game.ReplicatedStorage.GunInfo)
local player = game.Players.LocalPlayer
function onUpdate()
print("hmm")
local boughtInfo = boughtRequest:InvokeServer()
print("ummm")
end
player:WaitForChild("Credits").Changed:Connect(onUpdate)
And this is the server script that will receive it
local boughtRequest = game.ReplicatedStorage:WaitForChild("BoughtRequest")
function onBoughtRequest(player)
while (_G.boughtArray[player.userId] == nil) do
wait(0.1)
end
return _G.boughtArray[player.userId]
end
boughtRequest.OnServerInvoke = onBoughtRequest
The local script prints hmm, but not ummm. And I believe I am doing everything right, so I don’t know what is wrong. It just won’t connect, I tried putting prints in the receiving function and it wouldn’t do anything at all.
I speculate the while loop on the server side never ends. Try adding some print statements above the while loop.
Do you know if _G.boughtArray exists? Using _G is generally frowned upon. Maybe consider using Attributes?
on the server side u started UserId with a lowercase “u” whish should have been UPPER case.
userId doesn’t exist and therfore it goes into an infinte loop because it is always nil. change it in both cases to player.UserId
and that should fix it.
Hope this helps.
Ok actually I see that it has nothing to do with the stuff inside, because it won’t work even when I do this.
function onBoughtRequest(player)
--[[
while (_G.boughtArray[player.userId] == nil) do
wait(0.1)
end
return _G.boughtArray[player.userId]
--]]
print("Received")
local thing = "DOES IT WORK????"
return thing
end
boughtRequest.OnServerInvoke = onBoughtRequest
So it has something to do with the function connection itself I guess…maybe…
I checked the hub though and it looks correct