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

how would i make a value that changes to half it value?

how can i make it so that when on person touches a part then a value will change to half its value? this is the script i have in the part right now

function Touched(hit)
	local b = hit.Parent:FindFirstChild("Humanoid")
	if b ~= nil then
		game.ReplicatedStorage.WaitTime.Value = 0.5
	end
end

script.Parent.Touched:connect(Touched)

3 comments

0
  • .5 not = .5
0

Check out my answer!

0

This is exploitable.

2 answers

✓ Accepted answer

To half the value of something you will need to use /2 which in basic math means divide by 2. For example:

i = 1
a = i / 2

Now a is half of I.

For you, you will need to:

function Touched(hit)
    local b = hit.Parent:FindFirstChild("Humanoid")
    if b ~= nil then
        game.ReplicatedStorage.WaitTime.Value = game.ReplicatedStorage.WaitTime.Value / 2 --halves WaitTime.Value
    end
end

script.Parent.Touched:Connect(Touched)

For future reference:

  • = times, / = divide,
  • = addition,
  • = subtraction

Try to do

function Touched(hit)
    local b = hit.Parent:FindFirstChild("Humanoid")
    if b ~= nil then
local Time =  game.ReplicatedStorage.WaitTime.Value/2
        game.ReplicatedStorage.WaitTime.Value = Time
    end
end

script.Parent.Touched:connect(Touched)

4 comments

1

Explain why this works.

0

Do not have to explain it but the /2 divides the number value in half So there for if a number value is 4 it will be 2 6 will be 3

0

Also it is pretty annoying and kinda pisses me off down voting my answer even tho it is correct Abuse of power much

0

Corrupt, that is not abuse of power, you need to follow the community guidelines and explain your answer. Simply stating that something works is not helpful to that person in future, and I hope you realise that.

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