I was trying to do a script to when you’re walking, if you’re with bad luck, you slip and break ur neck.
Here is my script:
-->variables
local humanoid = script.Parent:WaitForChild('Humanoid')
local humanoid_root_part = script.Parent:WaitForChild('HumanoidRootPart')
local neck_break_sound = Instance.new('Sound')
local random = math.random(0, 1)
-->settings
neck_break_sound.SoundId = 'rbxassetid://1093102664'
neck_break_sound.Parent = humanoid_root_part
-->script
while wait() do
if humanoid:ChangeState() == Enum.HumanoidStateType.Running then
if random == 1 then
humanoid.Health = 0
neck_break_sound:Play()
end
end
end
In your loop, random doesn’t get updated - so once it is decided at the start of the script, it wont change. Your loop also has no wait time, so it is running every tick, which could become problematic.
while wait(someamountoftime) do -- put a time to wait here so it isn't checking every tick
local random = math.random(0, 1) -- maybe change 1 to a higher number to lower chances depending on how it plays out
if humanoid:ChangeState() == Enum.HumanoidStateType.Running then
if random == 1 then
neck_break_sound:Play() -- play the sound first in case sound bugs out on death (i dont do much work with sound so i woudln't know)
[[fire remote event here]]
end
end
end