I’m trying to make an orb that spawns when a pad is touched
The problem was the padTouched variable i created which for some reason didn’t work
local padTouched = room.Touched.Value
When i use it in an If statement it seems to not store the value
if humanoid and isTouched == false and padTouched == true then
But if i remove the .Value from the variable and put .Value in the if statment it works
local room = orb.Parent
if humanoid and isTouched == false and padTouched.Value == true then
My code:
-- Orb
local orb = script.Parent
local room = orb.Parent
local padTouched = room.Touched
local isTouched = false
local function heal(hit)
local character = hit.Parent
local humanoid = character:FindFirstChild("Humanoid")
local health = humanoid.Health
if humanoid and isTouched == false and padTouched.Value == true then
if health < 100 then
isTouched = true
if health < 75 then
health = 75 -- Set HP to 75
else
health += 20 -- Add 20 HP
end
room["Tutorial sign"].TextPart.SurfaceGui.TextLabel.Text = "Also you can't collect it if you have full HP"
room["Tutorial sign"].TextPart.SurfaceGui.TextLabel.TextSize = 25
orb:Destroy()
end
end
end
orb.Touched:Connect(heal)
I always never get the .Value of a value of some sort because when you call that variable, it is going to only get the value it was given at the start of the script.
Like when you are logically comparing that variable, you are actually not updating that variable. You would just be calling on it so lets say you did
local won = leaderstats.alive.Value
Then you did your fancy code while the player actually died and you change the won value on a different script, but you never updated the value in this script, and so at some point after the round you want to detect if the player was alive.
But the value true that has been set to that variable at the beginning was set there since you never updated it accordingly. To fix this you would have to do for example
won = leaderstats.alive.Value
and then your logical comparisons.
I hope this makes sense, but also I’m on mobile and the formatting for me can get challenging!