Adaks
(Adaks)
February 26, 2022, 4:19pm
#1
Hey, I have this server script in ServerScriptService:
game.Players.PlayerAdded:Connect(function(player)
local humanoid = workspace:WaitForChild(player.name):WaitForChild("Humanoid")
local disco = Instance.new("BoolValue", humanoid)
disco.Name = "canpush"
disco.Value = true
print(disco.Parent)
end)
It is sometimes ignored and the game doesn’t assign the players humanoid with the boolvalue, but sometimes it does - does anyone know the solution?
The script is supposed to insert a boolvalue inside game.Workspace.EveryPlayerThatJoins.Humanoid.canpush
game.Players.PlayerAdded:Connect(function(player)
playe.CharacterAdded:connect(function()
local humanoid = player.Character:WaitForChild("Humanid")
local disco = Instance.new("BoolValue", humanoid)
disco.Name = "canpush"
disco.Value = true
print(disco.Parent)
end)
end)
Perhaps they died?
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function()
local humanoid = workspace:WaitForChild(player.name):WaitForChild("Humanoid")
local disco = Instance.new("BoolValue", humanoid)
disco.Name = "canpush"
disco.Value = true
print(disco.Parent)
end)
end)
1 Like
Adaks
(Adaks)
February 26, 2022, 4:27pm
#4
Oh…yeah - I didn’t think it would be removed when the player has died, I’ll try it,.
Not removed, when the player respawn they are given a completely fresh character.
1 Like
Adaks
(Adaks)
February 26, 2022, 4:32pm
#6
I see, thanks for the support - honestly wouldn’t be able to figure it out
Forummer
(Forummer)
February 26, 2022, 9:42pm
#7
There’s a few issues with this, the .CharacterAdded
event’s parameter points/refers to the character model itself which was added, you don’t need to use the player’s name to index the workspace container for that player’s character. Additionally, the 2nd argument of Instance.new()
should be avoided when assigning values to the instanced object’s other properties.
I’ve discovered a pretty bad performance issue in one of top games that has to do with Instance.new and wanted to write about this, since this is not obvious unless you know the system inside out.
Tthere are several ways to create a ROBLOX object in Lua:
local obj = Instance.new(‘type’); fill obj fields
local obj = Instance.new(‘type’, parent); fill obj fields
local obj = util.Create(‘type’, { field1 = value1, … })
If you care at all about performance, please only use the first option - I wi…
local players = game:GetService("Players")
players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
local humanoid = character:WaitForChild("Humanoid")
local disco = Instance.new("BoolValue")
disco.Name = "canpush"
disco.Value = true
disco.Parent = humanoid
end)
end)
1 Like
Adaks
(Adaks)
February 27, 2022, 11:34am
#8
Thank you, I wasn’t aware of this.