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

How to clone a gui into a player after the player touches a part?

Asked by
hokyboy 270 Moderation Voter
5 years ago
function onTouched(hit)
   local player = game.Players:GetPlayerFromCharacter(hit.Parent)

game.ServerStorage.ScreenGui:Clone().Parent = game.Players.LocalPlayer.PlayerGui
  end


script.Parent.Touched:connect(onTouched)

Thats my script i tried it in a local script and a normal one do i need to use remote events? is there any other way?

0
put ScreenGui in StarterGui and put the script in ScreenGui , script.Parent.Enabled = true OnaKat 444 — 5y
0
Doesnt Seem To Work I put this in a local script function onTouched(hit) local player = game.Players:GetPlayerFromCharacter(hit.Parent) game.Players.LocalPlayer.PlayerGui.ScreenGui.Enabled = true end script.Parent.Touched:connect(onTouched) hokyboy 270 — 5y

1 answer

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

No, you don't need to use remote events or any sort of that complicated stuff, follow this:

GuiGiver = script.Parent
gui = script.Parent.ScreenGui

function GiveGui(part)  --"part" refers to the object that touched the brick (player)
local Playername = part.Parent.name --Finds the name of the part's parent that touched this part.
local cloned = gui:Clone()  --clone the gui and refer as it as "cloned".
if game:GetService("Players")[Playername].PlayerGui:FindFirstChild(gui.Name) then
    --If there is already a GUI called like that in PlayerGui, not do anything.
    else
    cloned.Parent = game:GetService("Players")[Playername].PlayerGui
    --Code above makes use of the variable with the value defined as the player's name
    end
end
GuiGiver.Touched:connect(GiveGui) 

Make sure that the part is anchored, and does not touch any other part, you can make it also not colliding. Here is my setup in workspace, and it works perfectly:

Image

if you have any question about this script, let me know :D!

note: use view source and paste that script into your Roblox editor, this answer box messes up the script a little bit, I guarantee that it will be easier to comprehend.

Ad

Answer this question