Walk into a object and tween a GUI

So, I struggled to describe it in such few words.
Basically, I want it to tween a GUI when they walk into an object.
Like this:

I already have most of the scripts for the GUI, I’m just stuck on how to make a GUI tween when I walk into an object. (I don’t remember what it’s called.)

Thanks to anyone who is able to help.

Just make a function so that when that is touched then it gets the playergui and tweens the animation.

2 Likes
--Easy! Use debounce and a Touched event. For example: 

script.Parent.Touched:Connect(function(touched(object) 
       --check if object is a player, then fire a remote event in order to tween the ui
end)

You’ll need to use the touched event! Create a Remote Event in Repliacted Storage and do the following:

local part = script.Parent
 
local function onPartTouched(otherPart)
	-- Get the other part's parent
	local partParent = otherPart.Parent
	-- Look for a humanoid in the parent
	local humanoid = partParent:FindFirstChildWhichIsA("Humanoid")
	if humanoid then
game.ReplicatedStorage.RemoteEvent:FireClient(partParent.Name)
	end
end
 
part.Touched:Connect(onPartTouched)

You’ll need a remote event and in a local script in StarterGui, do the following:

game.ReplicatedStorage.RemoteEvent.OnClientEvent:Connect(function()
--- GUI SCRIPT
end)

Read more about collisions here: Detecting Collisions | Documentation - Roblox Creator Hub

2 Likes
1 Like

I’m still a tad confused, as I don’t know much about scripting.


I’ve added what you’ve said, and I am still very confused.
I have added the GUI script into the second local script but I am stuck.
Sorry to be a bother.

Your GUI script and RemoteEvent is good. Change the local script in the part to a normal script.

1 Like


I’ve just got this error

The FireClient() first parameter must a player, instead do
local player = game.Players:GetPlayerFromCharacter(otherPart.Parent)
then fire it with that player
Try to use hit instead of otherPart it might be less confusing too.

2 Likes

I still don’t follow, sorry.
Where am I put/changing this.

local part = script.Parent

local function onPartTouched(otherPart)
	-- Get the other part's parent
	local partParent = otherPart.Parent
	-- Look for a humanoid in the parent
	local humanoid = partParent:FindFirstChildWhichIsA("Humanoid")
	if humanoid then
		game.ReplicatedStorage.RemoteEvent:FireClient(partParent.Name)
	end
end

part.Touched:Connect(onPartTouched)

ServerScriptService or child of the part

1 Like

Sorry, I’m still confused. Are you able to walk me through it?

Do this:

local function onPartTouched(otherPart)
	-- Get the other part's parent
	local partParent = otherPart.Parent
	-- Look for a humanoid in the parent
	local humanoid = partParent:FindFirstChildWhichIsA("Humanoid")
	if humanoid then
local player = game.Players:GetPlayerFromCharacter(otherPart.Parent)
game.ReplicatedStorage.RemoteEvent:FireClient(player)
	end
end

part.Touched:Connect(onPartTouched)

Sorry about that! Forgot that part.

1 Like


Just to confirm, is this correct?

1 Like

You need to connect the function to the event. add this at the bottom of your script:

part.Touched:Connect(onPartTouched)
1 Like

I can’t thank you enough, it works now. Thank you so much!
I will no doubt be making another post later on how to only do it for people who don’t own a gamepass but I’ll leave it for now.

Yet again, thank you so much.
And for those who may be interested in what I was doing, here you go:

1 Like

Your welcome! You did ask for an explanation so here is what messed up the first time: In order to fire the event to one player, you must have the player itself, not the character. That’s what I messed up on the first time. The function, GetPlayerFromCharacter, helps this issue to detect who the player is based on the parent.

1 Like