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