local RemoteEvent = game.ReplicatedStorage.RemoteEventTeam
local Atr = game.Workspace.ColVo.Transparency
function lo()
if Atr == 0 then
Atr = 0.1
elseif Atr == 0.1 then
Atr = 0.2
elseif Atr == 0.2 then
Atr = 0.3
elseif Atr == 0.3 then
Atr = 0.4
elseif Atr == 0.4 then
Atr = 0.5
elseif Atr == 0.5 then
Atr = 0.6
elseif Atr == 0.6 then
Atr = 0.7
elseif Atr == 0.7 then
Atr = 0.8
elseif Atr == 0.8 then
Atr = 0.9
elseif Atr == 0.9 then
Atr = 1
elseif Atr == 1 then
print(“1”)
else
print(“Error”)
end
end
RemoteEvent.OnServerEvent:Connect(lo)
Help please. This script skips all the elseif every time and immediately goes to the last else, but the conditions match. I don’t understand why it does that.
Sorry if it is written strangely or incorrectly, I use a translator.
The issue is that the value of Atr is only set once, when it needs to be set each time. Additionally, you will need to update the transparency within the script.
Some code that achieves the desired result is as follows:
local RemoteEvent = game.ReplicatedStorage.RemoteEventTeam
function lo()
local ColVo = game.Workspace.ColVo
if ColVo.Transparency == 1 then
print("1")
else
ColVo.Transparency += 0.1
end
end
RemoteEvent.OnServerEvent:Connect(lo)
When you initialized the variable Atr it gets the current transparency value
of game.Workspace.ColVo.
But if game.Workspace.ColVo’s Transparency changes the variable doesn’t change.
Example:
local value = instance.Transparency -- assume it's `1`
-- change the `Transparency` of `instance`
instance.Transparency = 0
print("past value: ".. value, "\ncurrent value: ".. instance.Transparency)
--[[ output:
past value: 1
current value: 0
]]
To fix:
Just index the property everytime instance.Transparency (unless you need the past value)
This long chain of elseifs is not a good practice
I suggest @SeargentAUS 's answer