Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to do Plus and minus math?!? (+ - )?!?!

Asked by 6 years ago

I want to do like something like if u touch the brick then it will makes my walkspeed 10+ every time i walk on it i tried everything i could do and it wont work

script.Parent.Touched:connect(function(touched)
    touched.Parent.Humanoid.WalkSpeed = +10
end)


i want to add 10+ do my walkspeed but idk how

3 answers

Log in to vote
0
Answered by 6 years ago

Do the followng.

local deb = false
script.Parent.Touched:Connect(function(touched)
    if touched.Parent:FindFirstChild('Humanoid') and not deb then
        deb = true
        touched.Parent.Humanoid.WalkSpeed = touched.Parent.Humanoid.WalkSpeed + 10
        deb = false
    end
end)

I edited some things to make it better.

2
the debounce here is pointless without a wait, else the debounce will deactivate immediately creeperhunter76 554 — 6y
0
add a wait on line 6 and push deb = false to line 7 ect abnotaddable 920 — 6y
0
IT WORKS NOW PERFECTLY!! ;D sadjsakdhkj 0 — 6y
0
Is this the shortest form we have in Lua for adding numbers? For example, you can quickly add in Java with Value ++ or Value += 16. Phantom1996 45 — 6y
0
Pretty sure its the shortest form, besides removing the spaces. hiimgoodpack 2009 — 6y
Ad
Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

simple,

script.Parent.Touched:Connect(function(touched)
    local humanoid = touched.Parent:FindFirstChild("Humanoid") 
    if humanoid then
        humanoid.WalkSpeed = humanoid.WalkSpeed + 10
    end
end)

please accept answer if you found this useful

0
you copied me hiimgoodpack 2009 — 6y
0
you copied me hiimgoodpack 2009 — 6y
0
i didn't copy you, i wrote this myself creeperhunter76 554 — 6y
0
yours is more simple !!! ;D sadjsakdhkj 0 — 6y
View all comments (2 more)
0
mines has a debounce to not set the speed to 9999999999999999999999999999999999999999999999999999999999999999999999999999. hiimgoodpack 2009 — 6y
0
sadjsakdhjk ones gives me 20 or 40 WalkSpeed+ sadjsakdhkj 0 — 6y
Log in to vote
0
Answered by
Azarth 3141 Moderation Voter Community Moderator
6 years ago
Edited 6 years ago
local touch_debounce = .5
local add_walkspeed = 10
local touchers = {}

local function addws(player, hum)
    hum.WalkSpeed = hum.WalkSpeed + add_walkspeed
    touchers[player.Name] = tick()
end

script.Parent.Touched:Connect(function(hit)
    -- Make sure we're actually a player and not an npc or other
    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
    if player then 
        local hum = player.Character:findFirstChild("Humanoid")
        -- Make sure we didn't reset on it
        if hum and hum.Health > 0 then 
            -- Check if we touched the part already
            -- This is so we can have a seperate wait for each player
            local touched_already = touchers[player.Name]
            -- If the player is already in the table.
            if touched_already then
                -- If the player passed the wait time to get more speed
                if tick() - touched_already > touch_debounce then 
                    print("Already in table and passed debounce time")
                    addws(player, hum)
                else
                    print("Waiting for debounce time to end")
                end
            else
                -- If the player isn't in the table yet
                -- add them and give them + 10ws
                print("Add to table")
                addws(player, hum)
            end
        end
    end
end)

Answer this question