Trouble with if/then statement

I’ve been trying to figure out a problem i’ve been having with my script, i’ve tried to find whats wrong with it but i really can’t.

–Here’s The Script

local Monster= game.Workspace.SpookyMonster
local OriginPosition = game.Workspace.SpookyMonster.Position.Z
local ReactionTime = 5
local DECAL_ID = “http://www.roblox.com/asset/?id=10198213112

function GetRandomPosition(part)

local x=math.random(-50.156, -46.506)
local y=math.random(1.5,33.65)
local z=math.random(-129.493,-44.393)
return Vector3.new(x,y,z)

end

while true do
Monster.Decal.Transparency=0
Monster.Position = GetRandomPosition()
task.wait(ReactionTime)
if Monster.Decal.Transparency==1 then
Monster.Decal.Transparency=0
else
print(“you lost”)
end
end

(The script is supposed to make the decal visible but it stays transparent)

Hello,
Firstly Roblox Lua Style guide constants are caps (REACTION_TIME) just like you did for DECAL_ID
Your decal ID doesn’t seem to lead to anything


have you tried with rbxassetid://10198213112 ?

Print Monster.Decal.Transparency to see if it’s 1 or not. If it is infact 1, and it is setting the transparency to 0, the decal might not be loading. Like Kolb said try rbxassetid://10198213112. When even is the Decal_ID variable used?

Ok so the first thing I noticed was that when you do Monster.Position = GetRandomPosition() you dont pass thru the part and in the function it says you are going to pass thru a part and you dont specify that it is optional in the script. (However based on the script I can see, you dont actually need to have the part there when you created the function) The second thing I noticed was that you continue to set the transparency of the Monster.Decal to 0 and you check if it is 1. But you never set it to 1. Not sure about this but thirdly; when you created a function I think it needs to be local function not just function. So the script would be the following:

local Monster= game.Workspace.SpookyMonster
local OriginPosition = game.Workspace.SpookyMonster.Position.Z
local ReactionTime = 5
local DECAL_ID = “http://www.roblox.com/asset/?id=10198213112 3”

local function GetRandomPosition()

 local x=math.random(-50.156, -46.506)
 local y=math.random(1.5,33.65)
 local z=math.random(-129.493,-44.393)
 return Vector3.new(x,y,z)
end

while true do
 Monster.Decal.Transparency=1
 Monster.Position = GetRandomPosition()
 task.wait(ReactionTime)
 if Monster.Decal.Transparency==1 then
 Monster.Decal.Transparency=0
 else
  print(“you lost”)
 end
end
1 Like

i tried it but i still got the same result.
sorry for the wait btw

1 Like

the DECAL_ID variable isn’t apart of the script, i just forgot to remove when trying to find a solution
sorry bout that

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.