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

Expected identifier when parsing expression, got 'then'?

so like my last post i am trying to make a game tips and tricks menu where if you walk near a object, it will show a gui. when you touch an invinsible brick, if will show the menu but i want it to close when you are not touching it. here is my script

script.Parent.Touched:Connect(function(hit)
    local Player = game:GetService('Players'):GetPlayerFromCharacter(hit.Parent)
    if Player then
        Player:WaitForChild('PlayerGui'):WaitForChild('Tips').Enabled = true
elseif
	
	player.PlayerGui.Tips.Enabled = false
    end
end)

2 comments

0

check my edit

0

edited again

1 answer

Elseif is followed by another argument, therefore you should replace it with else.

script.Parent.Touched:Connect(function(hit)
    local Pl = hit.Parent.Name
    local player = game.Players:WaitForChild(Pl)
    if player then
        player:WaitForChild('PlayerGui'):WaitForChild('Tips').Visible = true
    else
        player:WaitForChild('PlayerGui'):WaitForChild('Tips').Visible = false
   end
end)

25 comments

0

thanks but it says attempt to index nil with 'PlayerGui'

0

Edited

0

I write in the same time. Only 2 seconds different

0

We have write*

0

it says GetService is not a valid member of Workspace

0

edited again

0

and again

0

the problem is the player, after the else

0

edited again xd

0

thanks but it still wont work

0

it says infinite yield possible from the waitforchild

0

LOL, i got the name from the workspace then used tostring() to get it from Players lol xd

0

ion that case, is StarterGui.

0

No, its never startergui

0

Yeah, i confuse, sorry. Btw, u have write local player with the tostring and "If Player" <- remove the P

0

EDITED!!!!!! IT MIGHT WORK NOW!!!!!

0

^^

0

xD can't work!! you have write " local player" with a little "p" and after "if Player then" with a P

0

Ok yeah xD

0

i edited it

0

it says infinite yield but the gui turns on but the thing is it wont turn off after you walk away

0

wait

0

its not going to work sorry

0

i just checked what you wan tto do

0

i had to change visible to enabled and it still wont go away

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