Hello developers! I am currently trying to make an elimination game, and when you step into a place, AKA, touch a massive invisible, CanCollide off, part, in which inside of it, a local script is placed…
I want it so when you touch the part, the GUI is shown, saying, “You’re in!”
Here is the script below!
local inpart = script.Parent
local plr = game.Players.LocalPlayer
local text = script.Parent.Parent.intext
text.Visible = false
local function PopupReady(inpart)
text.Visible = true
end
local function PopupGone(inpart)
text.visible = false
end
inpart.Touched:Connect(PopupReady(plr))
inpart.TouchEnded:Connect(PopupGone(plr))
Currently, the gui pop up is constantly shown, even when you are not ‘inside’ the part.
Help would be good! Thank you in advance!
No you didn’t as I can see from the script, if you really want to use this method that I don’t suggest to use you will need to add a denounce that gets set to true for an amount of time you want when the part is touched and another one that is set to true when the function that fires when the player is in and to false with the other function, however this is not a good method to detect when the player is in and you should use Region3.
That happens because the function fires even if it’s not a player to touch it to fix it you have to add a check to control if the part is touched by a player for example checking if the part that touches it contain an humanoid
Hi There!
You can simply fix this by putting the script in StarterGui/StarterPlayerScripts and removing the (plr) argument where you call the function
like this -
An issue I would assume could occur is that .Touched either doesnt register OR it will simply fire multiple times over and over again. (same with .TouchEnded)
I would suggest you use Region3s to accomplish what you are looking for!
Probably yes, you have to tell the script where the part and the Gui is.
Also, you don’t have to write “inpart” as a parameter of the function, if you want to make sure the part is touched by a player then add a code that will run the function when a player’s character is touching the part…
Like this -
local Players = game:GetService("Players")
local function PopupReady(hit)
local player = Players:GetPlayerFromCharacter(hit.Parent)
if player ~= Players.LocalPlayer then
return
end
text.Visible = true
end
local inpart = workspace.inpart
local plr = game.Players.LocalPlayer
local text = game.StarterGui.ScreenGui.intext
local Players = game:GetService("Players")
local function PopupReady(hit)
local player = Players:GetPlayerFromCharacter(hit.Parent)
if player then
text.Visible = true
end
end
inpart.Touched:Connect(PopupReady)
try to add a variable that acts like a debounce like local PartTouched = false and set it where if the PartTouched = false when the player touches it then you can make the text visible you can do the same for the touch ended event. so your script would kinda look like this
local inpart = script.Parent
local plr = game.Players.LocalPlayer
local text = script.Parent.Parent.intext
local PartTouched = false
text.Visible = false
local function PopupReady(inpart)
if PartTouched == false then
text.Visible = true
end
end
local function PopupGone(inpart)
if InPart == true then
text.visible = false
end
end
inpart.Touched:Connect(PopupReady(plr))
inpart.TouchEnded:Connect(PopupGone(plr))
local inpart = script.Parent
local plr = game.Players.LocalPlayer
local text = script.Parent.Parent.intext
local PartTouched = false
text.Visible = false
local inpart = workspace.inpart
local plr = game.Players.LocalPlayer
local text = game.StarterGui.ScreenGui.intext
local Players = game:GetService("Players")
local function PopupReady(hit)
local player = Players:GetPlayerFromCharacter(hit.Parent)
if player then
text.Visible = true
print("Stepped in!")
end
end
local function PopupGone(hit)
local player = Players:GetPlayerFromCharacter(hit.Parent)
if player then
print("Stepped out!")
text.Visible = false
end
end
inpart.Touched:Connect(PopupReady)
inpart.Touched:Connect(PopupReady)
you need something like
local player = game.Players.LocalPlayer
in the touch connections
if player == plr then
(your stuff)
also u need the params for popupgone and the other one as (plr, part)
and u need if part.Parent:FindFirstChild(“Humanoid”)