How do i make a text print in output when a person touches a part?

I wanna make a script that when a person touch a part it will print a message in output.

Example

Me touches the part.
1 second later
@MasterAtTheWings (my username) win Easy Obby!

Please Read!

Do not include the “(my username)” when giving me a code (a.k.a script)

1 Like

put this in starterplayer or startercharacter, rename part to ur part

-- difine localplayer
local local_player = game:GetService('Players').LocalPlayer

local debounce

workspace.part.Touched:Connect(function()
	-- debounce logic to avoid the code firing multiple times
	if not debounce then
		debounce = true
		
		delay(1, function()
			print(local_player.Name .. 'has won')
			debounce = nil
		end)
	end
end)

im not good at scripting, even i had 3 years of studio experience, i continue noob at scripting!

and also i haved put the win part in a model

22:35:06.391 Torso is not a valid member of Accessory “Workspace.MasterAtTheWings.Accessory (Duffel_BagAccessory)”

what are you doing? put the script in starterplayer and change workspace.ur_part_name.Touched

I think is the reason!
My script:

-- difine localplayer
local local_player = game:GetService('Players').LocalPlayer

local debounce

workspace.EasyObby.EasyWinPart.Connect(function()
	-- debounce logic to avoid the code firing multiple times
	if not debounce then
		debounce = true

		delay(1, function()
			print(local_player.Name .. 'has won')
			debounce = nil
		end)
	end
end)

Ensure the script is a local script, otherwise you will not be able to reference the local player like you did in local_player

Make sure the function Connect is called using : as well

Should be

workspace.EasyObby.EasyWinPart:Connect(function()

This should work so long as the part is called EasyWinPart within the model EasyObby

It was an LocalScript! :grinning: :smiley: :smiley: :smiley: :smiley:

u forgot the .Touched

workspace.EasyObby.EasyWinPart.Touched:Connect(function()
1 Like