Hello, if you’re really new to scripting and want to make those speed bricks from speedrun, those killbricks from obby’s and jump bricks. You’ve come to the right place!
Let’s get started with the coding
[insert a normal script into the block you want as the speed, kill or, jump block]
script.Parent.Touched:Connect(function(hit)
local h = hit.Parent:FindFirstChild("Humanoid") -- gets the Humanoid of the player that touched it, h is our variable to get the humanoid.
if h ~= nil then
h.Health = 0 -- If you want to change this into speed do WalkSpeed = [number here]
-- if you want to do jumppower do h.JumpPower = [number here]
-- 16 is the set speed of everyone before they get the speedboost
-- 50 is the set jump of everyone before they touch the jumpboost block
end
end)
I hope this helps any new scripters.
If you know a shorter form of this script, just tell me because I also started scripting last month!
I recommend you identing your code so new scripters wont start with bad habits.
Also always declare variables with explicit meanings since you are doing the code for others not for yourself.
Code in it’s best explanated way would go like this:
local Brick = script.Parent -- Script needs to be inside the brick for this to work
Brick.Touched:Connect(function(touchedPart) -- Touched event is when a part touches other
local foundHumanoid = touchedPart.Parent:FindFirstChild("Humanoid") -- gets the Humanoid of the player that touched it, foundHumanoid is our variable to get the humanoid if there is one there.
if foundHumanoid then
foundHumanoid.Health = 0 -- If you want to change this into speed do WalkSpeed = [number here]
-- if you want to do jumppower do h.JumpPower = [number here]
-- 16 is the set speed of everyone before they get the speedboost
-- 50 is the set jump of everyone before they touch the jumpboost block
end
end)
Another way you can do this is by using the :TakeDamage() method of Humanoid. You can either do :TakeDamage(100) if you know the Health will always be that, or you can have it read Humanoid.MaxHealth property and deal damage based on that to fully kill them no matter their health.
(Granted this does the same thing as Humanoid.Health = 0. This is just an alternative way to do it.)
An also different way of killing the player is using :BreakJoints() on the character. You can also only kill players by using a function :GetPlayerFromCharacter() on the players service (game.Players) to check if a hit was from a player.