Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

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.

5 comments

2

the debounce here is pointless without a wait, else the debounce will deactivate immediately

0

add a wait on line 6 and push deb = false to line 7 ect

0

IT WORKS NOW PERFECTLY!! ;D

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.

0

Pretty sure its the shortest form, besides removing the spaces.

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

6 comments

0

you copied me

0

you copied me

0

i didn't copy you, i wrote this myself

0

yours is more simple !!! ;D

0

mines has a debounce to not set the speed to 9999999999999999999999999999999999999999999999999999999999999999999999999999.

0

sadjsakdhjk ones gives me 20 or 40 WalkSpeed+

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.