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

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

Asked by 9 years ago

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

Log in to vote
0
Answered by
yumtaste 476 Moderation Voter
9 years ago

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!

0
What's wrong with it? This has to be in a normal Script. yumtaste 476 — 9y
0
This answer works. There's nothing wrong with it... yumtaste 476 — 9y
0
This isn't actually the best way to get a player. EzraNehemiah_TF2 3552 — 9y
Ad
Log in to vote
0
Answered by 9 years ago

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)
0
Still Doesn't work. EzraNehemiah_TF2 3552 — 9y
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 BSIncorporated 640 — 9y
0
oops, fixed my mistake sorry LDZ! BSIncorporated 640 — 9y
0
Also, hit would be the part that touch the other part. It isn't the player also, it would be the character. EzraNehemiah_TF2 3552 — 9y
View all comments (5 more)
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 yumtaste 476 — 9y
0
Its obviously not the asker, his reputation isn't high enough to downvote BSIncorporated 640 — 9y
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. Rainwhal 0 — 9y
0
Your downvoting me because you think im a troll, nice job... Rainwhal 0 — 9y
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. yumtaste 476 — 9y
Log in to vote
0
Answered by 9 years ago

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!

Answer this question