How do I make a part which once I though it drops my speed by 20.
I’ve made this script inside of a part
script.Parent.Touched:connect(function(hit)
if hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid") then
hit.Parent.Humanoid.WalkSpeed -=20
end
end)
But it changes your speed into 0. I believe we have to check if our walk speed is a 0 but I am not entirely sure. If you can assist in any way please help.
Hit can be ran multiple times. If you want to check something on hit, then add a bool check to make sure it isn’t ran multiple times, and wait on it until a specific amount of time.
IE:
local bool = false
script.Parent.Touched:connect(function(hit)
if hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid") and not bool then
bool = true
hit.Parent.Humanoid.WalkSpeed -=20
wait(X)
bool = false
end
end)
Personally, I had to learn LUA by scratch from a diffrent programming language, I already have the neccessary skills to transfer, but for people who want to learn scripting, I think its a topic of learning the following things about coding:
Events
Functions
Effects
Variables
Usually that’s what I have my mind set on, Events are called like how a proximity prompt is triggered, or a hit detection goes off. Functions are like callable code snippets with arguments that can define what is used. Effects are what causes what to occur, like a screen going black or a part going invisible. A variable is a thing that stores data, between local/global. Global is defined as _G, and local is defined within the script with “local name = …”