Uoshaal
(Toon)
July 19, 2024, 9:35pm
#1
I made a script so that when the player enters the game he has a certain speed and health
plr.CharacterAdded:Connect(function(char)
local hum = char:WaitForChild("Humanoid")
hum.WalkSpeed =90
hum.MaxHealth = 100
end)
end`
but when I enter the game it continues at the default speed and yes, I’ve tried looking at some similar cases but I only found one and it didn’t work
Waiting for Answers
Rubin541
(Underscred)
July 19, 2024, 9:39pm
#2
I added game.Players.PlayerAdded:Connect(function(plr)
to the code and it seems to be working.
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
local hum = char:WaitForChild("Humanoid")
hum.WalkSpeed = 90
hum.MaxHealth = 100
end)
end)
J_Angry
(J_Angry)
July 19, 2024, 9:42pm
#3
Try checking if the player’s character already exists too, because the function might run after the player’s character was created.
if plr.Character then
local char = plr.Character
local hum = char:WaitForChild("Humanoid")
hum.WalkSpeed = 90
hum.MaxHealth = 100
end
Uoshaal
(Toon)
July 19, 2024, 9:42pm
#4
I also included this, I just cut it to the one that had the problem
Uoshaal
(Toon)
July 19, 2024, 9:46pm
#5
I executed the code but it didn’t work
slideterm
(slideterm)
July 19, 2024, 9:58pm
#6
You can change the CharacterWalkSpeed value in the Properties of StarterPlayer.
As for the health, make a script in StarterCharacterScripts.
local default_health = 1
local Character = script.Parent
local Humanoid = Character:WaitForChild("Humanoid")
Humanoid.Health = default_health
Humanoid.MaxHealth = default_health
slideterm
(slideterm)
July 19, 2024, 10:10pm
#7
Apologies. Changing the value doesn’t change the WalkSpeed.
This should work - place in a normal script inside of StarterCharacterScript.
local default_health = 1
local default_walkspeed = 1
local Character = script.Parent
local Humanoid = Character:WaitForChild("Humanoid")
Humanoid.Health = default_health
Humanoid.MaxHealth = default_health
script.Parent.Parent:FindFirstChild(Humanoid)
Humanoid.WalkSpeed = 0
1 Like
@Rubin541 's code should work. Are you sure you are executing this code in a server script?
system
(system)
Closed
August 2, 2024, 10:15pm
#9
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.