How can i add GUI appearing when player touched a part?

i don’t know where to put this topic at

local Block = script.Parent

local isTouched = false

local function fade()
	if not isTouched then
		isTouched = true
		for count = 10, 10 do
			Block.Speed:Play()
			Block.Transparency = count / 10
			wait(0.01)
	end
	    Block.CanCollide = false
	    wait(3)
	    Block.CanCollide = true
		Block.Transparency = 0
		isTouched = false
		Block.Respawn:Play()
	end
end

Block.Touched:Connect(fade)

what it does is when i touched a part, it fades and play a sound
currently i don’t know how to add when i touched a part, the GUI appears so how should i start? because it’s my first time to code and i’m still new to it

First of all, if this script you wrote is in a local script, it will not work.

2 Likes

This was written in “Script” as i do not use LocalScript

Well the simplest solution would be to clone a ScreenGui into the player’s PlayerGui

something like this

local ui = script.Parent.UI -- the location of the UI

part.Touched:Connect(function(part)
    local player = game.Players:GetPlayerFromCharacter(part.Parent)
    if player then
         ui:Clone().Parent = player.PlayerGui
    end
end)
1 Like

I’m a little confused, do you want the GUI that pops up to be server sided or client sided?

Basically meaning if you want everyone to see the GUI or only the player that touches the said block

1 Like

Because I was brain dead when I made the other post, here is the actual working solution to your problem.
You would want to use a RemoteEvent because RE’s can communicate between separate scripts using certain events. Put the RemoteEvent under ReplicatedStorage. Make sure to make a GUI and put it in StarterGui, change the transparency to 1.

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RE = ReplicatedStorage:WaitForChild("RemoteEvent")

script.Parent.Touched:Connect(function(touched)
	if game.Players:FindFirstChild(touched.Parent.Name) then
		local player = game.Players:FindFirstChild(touched.Parent.Name)
		RE:FireClient(player)
	end
end)

Basically just ensuring that whatever touched the part is an actual player, if it is an actual player it will fire the RemoteEvent.

Do the following in a LOCAL SCRIPT and put it in anywhere that is appropriate to be a parent of a local script, EX: StarterPack, StarterPlayerScripts, etc. Just don’t put it in ServerScriptService.

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RE = ReplicatedStorage:WaitForChild("RemoteEvent")
local StarterGui = game:GetService("StarterGui")
local gui = StarterGui:WaitForChild("yourGuiHere")

RE.OnClientEvent:Connect(function(player)
	--code here, change the gui transparency to 0
end)

Hope this helps!

1 Like