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

When you step on a block, how do you make it so my GUI pops up?

I have a car shop GUI I have made and I want it to open up by stepping on a part. I have a part down and a local script. The local script has

script.Parent.Touched:connect(function()
 local player = game.Players.LocalPlayer
 player.PlayerGui.Carshop.Frame.Visible = true
end)

3 answers

✓ Accepted answer

Technically, I'm not allowed to post scripts, but I'm going to do it anyway, and explain what each part does.

--make sure that this script is directly in the part

script.Parent.Touched:connect(function(part) --touched event
local player = game.Players:FindFirstChild(part.Parent.Name) --if the player steps on it, the player will exist. if, say, a random block touches it, "player" will be nil
if player then --makes sure player exists
player.PlayerGui:FindFirstChild("CarShop"):FindFirstChild("Frame").Visible = true --makes the GUI visible
end
end)

And there you have it. If you have any questions, comment. Please accept the answer and upvote if the answer is useful!

3 comments

0

What's wrong with it? This has to be in a normal Script.

0

This answer works. There's nothing wrong with it...

0

This isn't actually the best way to get a player.

The script doesn't know who the player is, so you need an argument for that

function Touch(hit) --hit is your argument, hit is the player that touched the block
	game.Players:FindFirstChild(hit.Parent.Name).PlayerGui.Carshop.Frame.Visible = true
end

script.Parent.Touched:connect(Touch)

9 comments

0

Still Doesn't work.

0

I literally took this script from a working block that does this exact thing, just changed mine from "Insert" to "Carshop" this will work

0

oops, fixed my mistake sorry LDZ!

0

Also, hit would be the part that touch the other part. It isn't the player also, it would be the character.

0

I think this asker is just a troll. We gave him 2 answers that work perfectly and do EXACTLY what he needs them to do, and he downvotes them

0

Its obviously not the asker, his reputation isn't high enough to downvote

0

I am not a troll, I didn't downvote anything. I just accepted the answer because I just tried it and it is right, thank you BSI.

0

Your downvoting me because you think im a troll, nice job...

0

Maybe it's not him that's the troll. I'm sorry I wrongfully accused you, and even though I didn't downvote all your answers/questions, I'll upvote them.

LocalScripts must be a child of a child of parent. Or in a character. So we need to put this in a REGULAR SCRIPT.

script.Parent.Touched:connect(function(character)
if game.Players:GetPlayerFromCharacter(character.Parent) then
 local player = game.Players:GetPlayerFromCharacter(character.Parent)
 player.PlayerGui.Carshop.Frame.Visible = true
end)

We also used the :GetPlayerFromCharacter() function. In the parameter you need the add the character. Regular scripts can't use LocalPlayer.


You didn't have anything in the parameter because it was a local script. Now we use the parameter here to check if it's a player(parameter was character). We also use the parameter to find the character.

I Hope this Helps!

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