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

Really Simple Help with Values?

Asked by 9 years ago

Okay, so I'm making a "real life simulator" game. And I want the toaster to do more damage the hotter it gets.

So I have 2 scripts, one is damage, the other is adding to damage.

This one is for the damage itself when touched:

Damage = script.Parent:WaitForChild("Damage").Value

script.Parent.Touched:connect(function(hit)
    if hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid") then
        local Humanoid = hit.Parent:WaitForChild("Humanoid")
        hit.Parent.Humanoid.Health = Humanoid.Health - Damage
    end
end)

And here's the one to add to the Damage Value: (It's inside of the value)

Value = script.Parent.Value

while true do
    script.Parent.Value = Value + 5
    wait(1)
end

The damage does -5, but I don't know why the value isn't going up.

I'm new to using values like this.

1 answer

Log in to vote
1
Answered by 9 years ago
local Damage = script.Parent.Damage.Value

script.Parent.Touched:connect(function(hit)
    if hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid") then
        local Humanoid = hit.Parent:FindFirstChild("Humanoid")
        hit.Parent.Humanoid:TakeDamage(Damage)
    end
end)

WaitForChild means the script waits until an Instance like Humanoid is added, FindFirstChild finds the first child named a specific name.

local Value = script.Parent.Value

while wait(1) do
    script.Parent.Value = Value + 5
end

Nothing wrong here.

I dunno if this works or not.

0
Thanks for improving the damage script, but it's still not adding to the value when I check on it in workspace while on play solo mode SpazzMan502 133 — 9y
Ad

Answer this question