Frame clones even though it's not called till touch

local RemoteEvent = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent")
local Part = script.Parent
local Debounce = false

RemoteEvent.OnServerEvent:Connect(function(Player)
	Part.Touched:Connect(function()
		if not Debounce then
			Debounce = true
			local PlayerGui = Player.PlayerGui
			local Gui = PlayerGui.ScreenGui
			local Frame = Gui.Frame
			local Clone = Frame:Clone()
			Clone.Parent = Frame.Parent
			wait(4)
			for i = 0, 1, .1 do
				wait(.01)
				Clone.Transparency = i
			end
			Clone:Destroy()
			wait(6)
			Debounce = false
		end
	end)
end)

Why does it clone without me touching the part? It clones when I start playing the game even though I dont touch the part.

https://gyazo.com/cdad2a942891f357e349f3bd3ff771b6

Bro you set a Player variable there on the function…
And then you said if it is touched then put a frame on that player.
So the frame goes to the player you set in the Player variable.
And part must be Anchored = false. So it touches the ground and sends the frame to you because you fired the Server.

Part.Touched has a parameter called otherPart. Use that to check if a player touched it.

Part.Touched:Connect(function(otherPart)
	local isPlayer = game.Players:FindFirstChild(otherPart.Parent.Name)
	if not Debounce and isPlayer == Player then
-- Your code

I don’t think this is related, but there is another issue with your code. If your Remote is fired more than once, then there will be more than one connection.

local RemoteEvent = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent")
local Part = script.Parent
local Debounce = false
local connection = nil

RemoteEvent.OnServerEvent:Connect(function(Player)
	if connection then return end
	connection = Part.Touched:Connect(function()
		if not Debounce then
			Debounce = true
			local PlayerGui = Player.PlayerGui
			local Gui = PlayerGui.ScreenGui
			local Frame = Gui.Frame
			local Clone = Frame:Clone()
			Clone.Parent = Frame.Parent
			wait(4)
			for i = 0, 1, .1 do
				wait(.01)
				Clone.Transparency = i
			end
			Clone:Destroy()
			wait(6)
			Debounce = false
		end
	end)
end)
1 Like

Yep, that’s right!!! But if you have a name-changing GUI or something else that changes your name. It can be buggy!!! So you should use the game.Players:GetPlayerFromCharacter(charModel).

Its weird if you coded it to change player name since that would break most stuff. But its safer to use GetPlayerFromCharacter.

Im on phone so too much typos

1 Like

I didn’t say anything about the Player’s name :smiley:.
Also, you can’t change a player’s name in explorer. And I never tried to change it by a script. So I think you can’t change it. But as I know you can change the Character name when you want to!!! This will change your name title above your head too because humanoid works this way.

It’s okay about the typos. They are not a problem when you can understand what it tries to tell :D.

1 Like