Script speed help

local bool = false
local X = 2 -- Replace with your desired wait time in seconds

script.Parent.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") and not bool then
        bool = true
        hit.Parent.Humanoid.WalkSpeed -= 18
        wait(X)
        bool = false
    end
end)

How do I make this script ONLY PUT A TIMER ON A SINGLE PLAYER so the rest won’t be affected by the cool down.

How would I also make it so if the players speed is less than 1 it will turn into 1.

Hi!

I might have a solution for your problem. You can create a table with every player that has a cooldown.
Let me write a script for you:

local check = {} -- creates table
local X = 2

script.Parent.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") and not table.find(check, player) then
        table.insert(check, player) -- place player in timeout
        hit.Parent.Humanoid.WalkSpeed -= 18
        wait(X)
        local index = table.find(check, player) -- get index of player
        table.remove(check, index) -- remove player out of timeout
    end
end)

Please tell me if something does not work!

Would I keep this in a script or the other one

Also how do i convert this into a percent a part which says if a players speed is less than 1 it will become 1

if hit.Parent.Humanoid.WalkSpeed < 1 then
    hit.Parent.Humanoid.WalkSpeed = 1
end

Does this work?

how would you make this kill a player

I’ll repurpose those anti exploits but instead it kills a player.

Hit.Parent.Humanoid.Health = 0

it would be much simpler if we put it in game ServerScriptService rather than adding a script.

ServerScriptService is for server sided scripts aka scripts meant for server use you should add the script into the part which is suppsoed to be touched

I don’t really understand what you mean by this

Like for anti exploints you die if ur health is bellow a number i’ll just make it 0 but for speed

1 Like

The thing is that this script wouldn’t work if we subtract the player’s speed.

roblox is hitting me with the warning and ban hammer for voice chat even though i clearly and obviously did nothing. It’s so foolish I can’t work on my games. It’s such a foolish way of moderation im going to have to send out emails all this nonsense.

You can just put it in a script that is child of the part.

Also i just saw i forgot something in the script, i hadn’t even defined the variable ‘player’!
Here’s a script in which you can do everything you want, including the things you asked for later:

local check = {} -- creates table
local X = 2

script.Parent.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") and not table.find(check, hit.Parent) then
        table.insert(check, hit.Parent) -- place player in timeout
        if hit.Parent.Humanoid.WalkSpeed - 18 < 1 then
            hit.Parent.Humanoid.Health = 0
        else
            hit.Parent.Humanoid.WalkSpeed -= 18
        end
        wait(X)
        local index = table.find(check, hit.Parent) -- get index of player
        table.remove(check, index) -- remove player out of timeout
    end
end)

I tested it, and it works for me! Tell me what you think, and hope this helped.

Change it to :FindFirstChildOfClass instead because it can see Humanoid.

So this is how it should be:

local bool = false
local X = 2 -- Replace with your desired wait time in seconds

script.Parent.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChildOfClass("Humanoid") and not bool then
        bool = true
        hit.Parent.Humanoid.WalkSpeed -= 18
        wait(X)
        bool = false
    end
end)

Also, don’t forget to change it to #help-and-feedback:scripting-support.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.