staffles
(riley)
April 2, 2021, 3:33pm
#1
Hello! I am attempting to make a simple script, a server script makes a value inside of the player upon joining and a client script will pick up that variable and will check it’s value. The issue is that the value is not able to be picked up for some reason, so I tried to just print the value’s name from the client script.
Here is the code:
Server code that creates variable:
game.Players.PlayerAdded:Connect(function(player)
local scareValue = Instance.new("BoolValue", player)
scareValue.Name = "ScareValue"
scareValue.Value = false
end)
Client code inside of StarterPlayerScripts
:
print(game.Players.LocalPlayer.ScareValue.Name)
Does anyone know a fix? Thanks for reading!
1 Like
My only assumption is that the LocalScript
is running first, which is resulting as a nil
value
You can try this inside the code:
local Player = game.Players.LocalPlayer
local Scare = Player:WaitForChild("ScareValue")
print(Scare.Name)
Basically, it’s running too fast for the server to even create the value ahead of time for the client script to print
1 Like
staffles
(riley)
April 2, 2021, 3:59pm
#3
I see, I will try this. Such an easy fix, thank you!
staffles
(riley)
April 2, 2021, 4:01pm
#4
It worked! Thank you so much, and have an amazing day!
1 Like
Relukn
(Nickk)
April 2, 2021, 9:00pm
#5
Just a tip, don’t use instance.new with parent argument.
You should do this:
game.Players.PlayerAdded:Connect(function(player)
local scareValue = Instance.new("BoolValue")
scareValue.Name = "ScareValue"
scareValue.Value = false
scareValue.Parent = player
end)
Rather than this:
game.Players.PlayerAdded:Connect(function(player)
local scareValue = Instance.new("BoolValue", player)
scareValue.Name = "ScareValue"
scareValue.Value = false
end)
You can read about why here .