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

Player Gui Appear On Touched, Wont Work?

Asked by 5 years ago

Making A Gui Appear On Touch From The Player Gui, But It Aint Working, Anybody Got Any Ideas? Here Is My Script:

1local plr = game.Players.LocalPlayer
2 
3function onTouched(part)
4    plr.PlayerGui.GameGui.SwordShop1.Visible = true
5end
6 
7script.Parent.Touched:connect(onTouched)

2 answers

Log in to vote
0
Answered by 5 years ago

You can’t get the local player on a server script. A server script is just a regular script. You can get the player within the touched event by calling a function :GetPlayerFromCharacter()

A character is just the interactive and visual appearance of the player, like the hats, the shirts and everything else. Whenever a character touches a brick only their body parts (head, torso, right arm) will be seen as “touched”.

To get a player from the character you get the character which is part.Parent. You can store it in a variable too. You also need to check if “part” is actually part of the parent. I included that for you.

Your script fixed will be:

1function onTouched(part)
2     if part.Parent:FindFirstChild(“Humanoid”) then
3          local Player = game.Players:GetPlayerFromCharacter(part.Parent)
4          Player.PlayerGui.GameGui.SwordShop1.Visible = true
5     end
6end
7 
8script.Parent.Touched:connect(onTouched)
0
Where'd you get these quotation marks? “” Tymberlejk 143 — 5y
0
I have no idea. Sensei_Developer 298 — 5y
0
holy you are right, it's probably a rare bug 123nabilben123 499 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

In order to get the PlayerGui with a server script, try using RemoteEvents. Here, let me show you the ServerScript.

1) First, place a RemoteEvent inside ReplicatedStorage.

2) Get the .Touched script and write this;

1script.Parent.Touched:Connect(function(hit)
2    if hit.Parent:WaitForChild('Humanoid') then
3        game.ReplicatedStorage.RemoteEvent:FireClient()
4    end
5end)

3) Now, place a LocalScript inside of your SwordShop1 and write;

1game.ReplicatedStorage.OnClientEvent:Connect(function()
2    script.Parent.Visable = true
3end)

Voila! I hope I helped. If you don't understand something, then feel free to ask me on the comments.

0
Visible not visable greatneil80 2647 — 5y

Answer this question