I have a block on a model that when it is hit by another car the other car falls apart, I use :BreakJoints() for this so if a player gets hit they die. I was trying to make it so that if the player gets hit they don't die but instead the humanoid sits and the crash sound still plays but the player doesn't die. I'm new to scripting so i cant get that advanced however my code was kinda getting confusing to understand as well. Just please tell me if you can help because the game is just a fun game to mess around in by crashing brick built cars and I want to be able to crash into my friends too and see how much fun me and my friends can have. So if you can help thanks.
function crash(hit) if hit.name ~= "Humaoid" then hit:BreakJoints() script.Parent.Crash:Play()
if hit.Name == "Humanoid" then local humanoid = game.Players.LocalPlayer.Character:FindFirstChild("Humanoid") if humanoid then humanoid.Sit = true script.Parent.Crash:Play() wait(5) humanoid.Sit = false end end end
end script.Parent.Touched:Connect(crash)
The crash part of the script works just fine, just wanted to see if I could make it so players wouldn't die.
Hello! This should help.
if hit.Parent:FindFirstChild("Humanoid") then local humanoid = game.Players.LocalPlayer.Character:FindFirstChild("Humanoid") game.ReplicatedStorage.Event:FireServer()--Name of your RemoteEvent script.Parent.Crash:Play() end -- Serverscript game.ReplicatedStorage.Event.OnServerEvent:Connect(function(plr) plr.Character.Humanoid.Sit = true wait(5) plr.Character.Humanoid.Sit = false end)
Hope this helps! You problem: You can’t hit a humanoid. So, I just check if that object has a humanoid.
if hit.Name == "Humanoid" then local humanoid = game.Players.LocalPlayer.Character:FindFirstChild("Humanoid") if humanoid then humanoid.Health = 1000 -- Set it to 1000 or more humanoid.Sit = true script.Parent.Crash:Play() wait(5) humanoid.Health = 100 -- Set it back to default humanoid.Sit = false end end end
Try this, what this script does that it sets the player health to around 1000, and after 5 seconds, it sets it back to 100. Tell me if there any errors.