Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Help So that a Player doesn't get killed in my car crash system?

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.

3 comments

0

You can increase the health of the humanoid to around a 100 and after the car has crashed, set it back to 100.

0

BreakJoints() does not care how much health does a humanoid have.

0

Oh lol i forgot

2 answers

    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.

1 comment

0

It doesn't work because I have to use breakjoints() because thats the easiest way to break bricks on a model. The Character still dies. I Just want to find a way that if there is a humanoid it doesn't break joints and makes the player sit.  So if you have any ideas on how to do that please help with that.

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.

5 comments

0

Hello Alex, It solves the character dying however the character doesn't sit I use R15 that might be why. But the in properties of the Humanoid Sit doesn't change to true?

0

Hmm, are you using a local script?

0

Oh, you are. You have to create a remote vent.

0

Event*.

0

Here, I will apply edits into my script.

This discussion is preserved as it was. New answers, comments, and votes are closed.