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

How do I make this script if a player touched a part then show GUI?

Asked by
130363 67
7 years ago

I am making a game whee when you touch a brick if will open a Gui to ask for conformation to teleport to the shop and it also says Worspace is not a valid member of DataModel

script.Parent.Touched:connect(function(player)
    local teleportgui = game.Worspace.TeleportGui:Clone()
    teleportgui .Parent = game:GetService("StarterGui")
end)
0
There shouldn't be an error, to my knowledge. Also line 3..... Your copying to startergui which won't work, because the player must reset for it to appear, and it appears for all users too... H4X0MSYT 536 — 7y
0
You're* Nik1080 24 — 7y

2 answers

Log in to vote
1
Answered by
ARTEK22 135
7 years ago
Edited 7 years ago

Problem

I've caught 2 problems in your script. 1. You made a typo. 2. You parented the gui into "StarterGui" which is the gui which every player gets upon joining. 3. You didn't even check if a player touches the brick instead of a normal part.

Solution

Just simply correct the worspace into workspace and try to get the player's PlayerGui

script.Parent.Touched:connect(function(part) -- the part which touched the brick
    local parent = part.Parent -- the parent of the part
    local player = game.Players:GetPlayerFromCharacter(parent) -- check if the parent is a player character
    if player then -- if the player matching the character is found
        local teleportgui = game.Workspace.TeleportGui:Clone() -- i corrected the workspace for you <3
        teleportgui .Parent = player.PlayerGui -- the folder for guis of the player
    end
end)

A tip (not a robux tip lol)

No need for that, but you should make the script check if the player already has the gui which will avoid giving the player multiple guis or you should put a debounce. http://wiki.roblox.com/?title=Debounce

Here is the option with the gui checker:

script.Parent.Touched:connect(function(part) -- the part which touched the brick
    local parent = part.Parent -- the parent of the part
    local player = game.Players:GetPlayerFromCharacter(parent) check if the parent is a player character
    if player then -- if the player matching the character is found
        if not player.PlayerGui:FindFirstChild("TeleportGui") then -- if the gui is NOT found
            local teleportgui = game.Workspace.TeleportGui:Clone() -- i corrected the workspace for you <3
            teleportgui .Parent = player.PlayerGui -- the folder for guis of the player
            teleportgui.Name = "TeleportGui" -- change the name, we are gonna search for it
       end
    end
end)

Comment on this if your script still errors so i'll just check the script again just incase i made a mistake.

0
Error:(5,32) Expected '(','{' or <string>, got ':' 130363 67 — 7y
0
I have a question.... So when the player touches a part, it touches the player model and the parent the player model is the thing that contains Backpack, PlayerScripts, and etc. 130363 67 — 7y
0
@130363 Which script did you get the error on? The solution or the tip? And yes. ARTEK22 135 — 7y
0
Oh, sorry. Change the line 5 in the second script into if not player.PlayerGui:FindFirstChild("TeleportGui") then -- if the gui is NOT found ARTEK22 135 — 7y
View all comments (2 more)
0
Thanks 130363 67 — 7y
0
10/10 130363 67 — 7y
Ad
Log in to vote
-1
Answered by 7 years ago

Line 2: You are missing the 'K' in Workspace.

Answer this question