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

I don't know whar's wrong with this if not FindFirstChild loop?

Asked by 6 years ago
while true do
wait(0.1)
if not player.Character:findFirstChild("StartMenu") then
 game.StarterGui.ShopButton.Frame.Visible = true
 end
end

0
Please explain your question and not just post code, hoping that people will understand. Zenith_Lord 93 — 6y

2 answers

Log in to vote
0
Answered by
Fifkee 2017 Community Moderator Moderation Voter
6 years ago

FindFirstChild, not findFirstChild..? Also, just do while wait() do. And try enabling the recursive property. Is there any errors?

Ad
Log in to vote
0
Answered by 6 years ago

I'm BlackOrange and I'm here to help!

Firstly: I'm not sure what you are attempting to do. But there is a few ways to improve this script.

Deprecated Objects:

on line 3 of your script, you used findFirstChild() which is deprecated (meaning Roblox no longer supports it / outdated). Instead you should be using :FindFirstChild() just capitalize the f

Player:

When it comes to players, it's really easy to get the player through a local script.

local plr = game.Players.LocalPlayer

But when it comes to script, you will have to find a way to get player (a common way is RemoteEvents or game.Players.PlayerAdded(plr)) anyway, since your dealing with GUI, I'm gonna assume you are using a LocalScript (which you should if you aren't). You should also make a character variable, sometimes Character would return nil (death).

local plr = game.Players.LocalPlayer
local Char = plr.Character or plr.CharacterAdded:Wait() -- if not plr.Character then waits for the character to be added

while true do
    wait(0.1)
    if not Char:FindFirstChild('StartMenu') then

    end
end

This is what we have so far. Now, I'm not sure why StartMenu would be in a character (unless it's a BoolValue or String) but since I have no clue what you are attempting to do I will go on to other things you can improve.

StarterGui:

StarterGui is where whatever is inside of it (child of). It will all be cloned / duplicated into a object called PlayerGui which is all UI at play. Since PlayerGui is in player then you would get it from player as well.

local plr = game.Players.LocalPlayer
local Char = plr.Character or plr.CharacterAdded:Wait() -- if not plr.Character then waits for the character to be added

while true do
    wait(0.1)
    if not Char:FindFirstChild('StartMenu') then
        plr:WaitForChild('PlayerGui').ShopButton.Frame.Visible = true
    end
end

Last Notes:

I have noticed a few things such as ShopButton. To make a Button or frame visible, you would need a ScreenGui. I'm not sure what StartMenu is but I believe there are better ways to check.

If this doesn't work that should only be normal. You don't have ScreenGuis and you have a while true do loop which I don't understand why. IF this is a player dying thing the Humanoid is inside of Character which has a Died event. Used like so: Char.Humanoid.Died:Connect(function() Runs when the player dies.

Well this is only code improvement, best of luck.

Answer this question