Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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?

2 comments

0

put ScreenGui in StarterGui and put the script in ScreenGui , script.Parent.Enabled = true

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)

1 answer

✓ Accepted answer

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.