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

i made it so that when you touch a brick it brings up a gui but... ?

Asked by 7 years ago

it words just fine in studio when i test the game but online the gui doesn't come up when you touch the brick

heres the script:

local Part = script.Parent
local Player = game.Players.LocalPlayer

Part.Touched:connect(function()
    game.Players.LocalPlayer.PlayerGui.Shop.Frame.Visible = true

end)
0
works* beastboy8171 5 — 7y

1 answer

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

Hey beastboy8171,

There is a problem with your script. The problem is: It's a ServerScript and you can't access LocalPlayer from ServerScripts and you can't use LocalScripts in the server. You must only use ServerScripts in the server and you must only use LocalScripts in the Client. But, there's a solution to how you can go about getting the player from the Server Script and be able to do what you are doing, just from a simple ServerScript. The event .Touched has a parameter of the part which is touching. In order to get to the Player, you must make sure that the part which is touching is from the Character of a player. This is most commonly checked by checking if you can find the object Humanoid inside of the parent of the part which is touching. So, all you have to do is use the :FindFirstChild() method for the part's parent and try to see if it contains a Humanoid. Here is the wiki page about that method and below is a personal example.

local hum = part.Parent:FindFirstChild("Humanoid")

After that just check it's existence with a simple if statement. So afterwards, if it passes the if statement, you know that the object that touched the Part is from a Character. So, you can easily define Character as being the object's parent. Now, here you might get introduced to a new method that you didn't know about. Let me introduce you to a simple method you can use to get the Player from the Character. It's called :GetPlayerFromCharacter I know right, pretty simple. Here is the wiki page for it and below is a personal example.

local character = part.Parent
local player = game:GetService("Players"):GetPlayerFromCharacter(character)

After you have the parent, you can just locate the PlayerGui and find what you need and mutate it's properties as you may like. I hope this helped and have a great day/night.

~~ KingLoneCat

1
Why the need for the enlarged & emphasized words? e_e From my perspective, it makes it hard to read and understand certain points that you're trying to explain. TheeDeathCaster 2368 — 7y
0
Thanks! beastboy8171 5 — 7y
0
@TheeDeathCaster, thank goodness not everybody is like you. KingLoneCat 2642 — 7y
Ad

Answer this question