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

An if statement doesn't work the way I planned?

I am having a problem with an if statement, I am trying to do so the code won't execute if there is an object in the workspace called "Laser" and if he has a child that is named the Player's name.

if game.Workspace:FindFirstChild("Laser"):FindFirstChild(Player.Name)then
    print("LaserInActionAlready")
    elseif not game.Workspace:FindFirstChild("Laser"):FindFirstChild(Player.Name)then
wand.Activated:Connect(function(Mouse)
local Mousehit = game.Players.LocalPlayer:GetMouse().Hit
local Mousehitp = game.Players.LocalPlayer:GetMouse().Hit.p
if script.Busy.Value == true then 
script["Aqua eructo"].Disabled = true
end
if script.Busy.Value == false then
if enabled == true then
    enabled = false
if not script["Aqua eructo"].Disabled == true then
script.Done.Value = false
script["Aqua eructo"].RemoteEvent:FireServer(Mousehitp,Mousehit)

Why the first 3 lines won't make sure that the remote event doesn't get fired if there is an object called "Laser" and inside it an object with the character's name that is my question, I would be happy if someone could help.

2 comments

0

If you haven't tried already you could put a stringvalue in there, and put the name in there, then you'd do if game.Workspace:FindFirstChild("Laser").stringvalue.Value==Player.Name then, this technically isn't an answer so I'm not posting it as that.

0

Ill try

1 answer

This is because the script you have isn’t wrapped in a function, loop, or event.

Since you didn’t wrap it into one of these, the if statements automatically ran, and checked only once. Another error is you put your Tool.Activated event inside an of statement, which is not okay. On top of that, you tried to pass the mouse as a parameter. The Tool.Activated event has no parameters.

2 comments

0

I have tried to put it inside of a OnServerEvent scope but it didn't work.

0

I don't see how me putting it in a function can help with my problem.

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