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?
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:
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.