Can anyone help me fix this code?
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 + 13 < 1 then
hit.Parent.Humanoid.WalkSpeed = 1
else
hit.Parent.Humanoid.WalkSpeed += 13
wait(X)
local index = table.find(check, hit.Parent) – get index of player
table.remove(check, index) – remove player out of timeout
end
end)
This code is a bit painful to read, use three “`” at the beginning and end for proper formatting.
What does your code do by the way? Would be very helpful.
Also, I know for certain that changing player walkspeed works if you change it client sided, so try that maybe.
Additionally, in the line where you check if humanoid walkspeed + 13 < 1, that implies that the walkspeed is -12 or lower, and that isn’t possible I think
Like @Noobik35 said, you’re trying to check if the Humanoid.Walkspeed is below 0, and that shouldn’t be possible, however the else condition still works completly fine for me, I tried it out in Studio and my character actually increases speed, using the same script you posted here. Can you try printing something inside it to see if it actually executes?
default walkspeed is 15 so checking if it’s less than 1 is just always going to break it also you are putting < meaning only if it’s less 1 so 0 than if you put <= then it would mean 1 or below.
-- maybe use a local script instead? (inside of StarterPlayerScripts)
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local timeout, length = false, 2 -- timeout var instead of checking a table of players
local Increase = 13 -- increase by 13
local Max = 50
workspace:WaitForChild("Part").Touched:Connect(function(hit) -- you could get the part from workspace
if hit.Parent ~= Character then -- check if you are touching the part
return
end
if not timeout then
if (Humanoid.WalkSpeed + Increase) <= Max then -- check if increasing would go over the max
Humanoid.WalkSpeed += Increase
timeout = true
end
-- set timeout to false after 2 seconds when setting speed
wait(length)
timeout = false
end
end)
not sure what you were trying to do with
if hit.Parent.Humanoid.WalkSpeed + 13 < 1 then
hit.Parent.Humanoid.WalkSpeed = 1
else
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 + 13 < 1 then
hit.Parent.Humanoid.Health = 0
else
hit.Parent.Humanoid.WalkSpeed += 13
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)
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 + 13 < 1 then
hit.Parent.Humanoid.Health = 0
else
hit.Parent.Humanoid.WalkSpeed += 13
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)"
It just worked. I will come back tomorrow and show u a video of what is still wrong. Some time it changes it but for some parts it doesn’t. Nvm prob copied wrong script.