|
| 11 Feb 2016 05:55 PM |
server script: game.Players.PlayerAdded:connect(function(player) local Stage = game:GetService("ServerStorage").StatFolder:FindFirstChild(player.Name).Stage print 'stage found' NotifyUpdateStage:FireClient(Stage) print 'fired from server' Stage.Changed:connect(function() NotifyUpdateStage:FireClient(Stage) end) end)
--------- local script:
local player = game.Players.LocalPlayer local TotalStages = script.Parent.Parent.Parent:WaitForChild("Stages") local NotifyStageUpdate = game:GetService("ReplicatedStorage"):WaitForChild("Remote"):WaitForChild("NotifyStageUpdate")
print 'progress bar loaded'
NotifyStageUpdate.OnClientEvent:connect(function(Stage) print 'client event received' Stage = Stage.Value script.Parent.Size = UDim2.new(Stage / TotalStages.Value, 0, 1, 0) script.Parent.StageLabel.Text = "STAGE "..Stage.Value.."/"..TotalStages.Value end)
--------------- Stats are being stored in serverstorage like so: ServerStorage>"StatHolder"Player1>Stage
Trying to update the player's progress bar when their Stage is changed.
It only prints 'progress bar loaded' but nothing else, even when the stage value is changed. What am I doing wrong? |
|
|
| Report Abuse |
|
|
|
| 11 Feb 2016 06:27 PM |
| so i changed FireServer's argument to FireServer(player, stage) and onclientevent's to player,stage as well but now i get an error saying Stage is a nil value |
|
|
| Report Abuse |
|
|
|
| 11 Feb 2016 06:34 PM |
server script
game.Players.PlayerAdded:connect(function(player) Stage = game:GetService("ServerStorage"):WaitForChild("StatFolder"):WaitForChild(player.Name).Stage NotifyStageUpdate:FireClient(player, Stage) --// needs to set progress bar when player first joins print 'fired from server' Stage.Changed:connect(function() NotifyStageUpdate:FireClient(player, Stage) --// update progess bar when stage is updated print 'fired from server' end) end)
local script
local player = game.Players.LocalPlayer local TotalStages = script.Parent.Parent.Parent:WaitForChild("Stages") local NotifyStageUpdate = game:GetService("ReplicatedStorage"):WaitForChild("Remote"):WaitForChild("NotifyStageUpdate")
print 'progress bar loaded'
NotifyStageUpdate.OnClientEvent:connect(function(player, Stage) print 'client event received' script.Parent.Size = UDim2.new(Stage.Value / TotalStages.Value, 0, 1, 0) script.Parent.StageLabel.Text = "STAGE "..Stage.Value.."/"..TotalStages.Value end)
------- it's printing everything but throwing an error on this line saying stage is a nil value
script.Parent.Size = UDim2.new(Stage.Value / TotalStages.Value, 0, 1, 0)
helppp |
|
|
| Report Abuse |
|
|
TimeTicks
|
  |
| Joined: 27 Apr 2011 |
| Total Posts: 27115 |
|
|
| 11 Feb 2016 06:44 PM |
--server script
local notify = game.ReplicatedStorage:WaitForChild("StageUpdate") local stats = game.ServerStorage.StatFolder
game.Players.PlayerAdded:connect(function(player) local stage = stats[player.Name].Stage notify:FireClient(player, stage.Value) stage.Changed:connect(function() notify:FireClient(player, stage.Value) end) end)
--local script
local player = game.Players.LocalPlayer local stage = script.Parent.Parent.Parent:WaitForChild("Stage") local notify = game.ReplicatedStorage:WaitForChild("StageUpdate")
notify.OnClientEvent:connect(function(player, val) script.Parent.Size = UDim2.new(val / stage.Value, 0, 1, 0) script.Parent.StageLabel.Text = "STAGE "..val.."/"..stage.Value end) |
|
|
| Report Abuse |
|
|
|
| 11 Feb 2016 07:00 PM |
| had to edit your code a bit to make it fit but it still says that 'val' is a nil value..i know its there |
|
|
| Report Abuse |
|
|
| |
|
|
| 11 Feb 2016 07:40 PM |
it loads on the server but when i use it as an arg in fireserver it says it's nil
whyyyy |
|
|
| Report Abuse |
|
|
| |
|
gangman67
|
  |
| Joined: 04 Jun 2011 |
| Total Posts: 798 |
|
|
| 11 Feb 2016 08:06 PM |
| If your using his code I belive that the value is being passed as the player parameter, in the local script "notify.OnClientEvent:connect(function(player, val)", player shouldnt be a parameter |
|
|
| Report Abuse |
|
|
|
| 11 Feb 2016 08:28 PM |
| Player has to be passed in FireServer so it needs to be received in OnClientEvent right? |
|
|
| Report Abuse |
|
|
gangman67
|
  |
| Joined: 04 Jun 2011 |
| Total Posts: 798 |
|
|
| 11 Feb 2016 08:33 PM |
| When the server is firing to the client you need a player, but on the clients end the player isn't a parameter |
|
|
| Report Abuse |
|
|
|
| 11 Feb 2016 09:29 PM |
| I removed the player arg, same error |
|
|
| Report Abuse |
|
|
| |
|
| |
|
|
| 12 Feb 2016 08:14 AM |
| Tried having the stats and the remote event in workspace and same error |
|
|
| Report Abuse |
|
|
|
| 12 Feb 2016 08:30 AM |
| I'll try some things in Studio |
|
|
| Report Abuse |
|
|
| |
|
Tigerism
|
  |
| Joined: 26 Aug 2015 |
| Total Posts: 561 |
|
|
| 12 Feb 2016 08:40 AM |
| u can't pass objects in an argument via remoteevents or remotefunctions |
|
|
| Report Abuse |
|
|
|
| 12 Feb 2016 08:42 AM |
| if val is returning nil are you sure you have it all in the same spelling that's only reason I can imagine it's returning nil right now. |
|
|
| Report Abuse |
|
|
Tigerism
|
  |
| Joined: 26 Aug 2015 |
| Total Posts: 561 |
|
|
| 12 Feb 2016 08:43 AM |
you need to pass the actual stage value, not the object itself
so Stage.Value |
|
|
| Report Abuse |
|
|
|
| 12 Feb 2016 08:44 AM |
@Tiger Just tried that
"attempt to perform arithmetic on local 'Stage' (a nil value)" |
|
|
| Report Abuse |
|
|
|
| 12 Feb 2016 08:46 AM |
NotifyStageUpdate.OnClientEvent:connect(function(player, Stage) print 'client event received' local size = Stage / TotalStages.Value script.Parent.Parent.Size = UDim2.new(size, 0, 1, 0) script.Parent.Text = "STAGE "..Stage.."/"..TotalStages.Value end)
on this line: local size = Stage / TotalStages.Value
I couldn't put "Stage.Value" in here |
|
|
| Report Abuse |
|
|
Tigerism
|
  |
| Joined: 26 Aug 2015 |
| Total Posts: 561 |
|
|
| 12 Feb 2016 08:47 AM |
use tonumber on the math part and make sure an actual value is inside Stage. so like put
if not Stage then return end
to stop the rest of the script if the value isn't even there
also do print(Stage) on the local script part to see what's even being sent |
|
|
| Report Abuse |
|
|
Tigerism
|
  |
| Joined: 26 Aug 2015 |
| Total Posts: 561 |
|
| |
|
|
| 12 Feb 2016 08:50 AM |
print(Stage) local size = tonumber(Stage) / TotalStages.Value
Printed nil... |
|
|
| Report Abuse |
|
|