Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How would I turn my Touched into an only player touched?

I have a script where if a player steps over the object, it will move to a different spot smoothly, but my problem is, I don't know how to change a regular Touched, into a player touch. Script:

local TweenService = game:GetService("TweenService")

local part = workspace.ManholeCover
part.Position = Vector3.new(-30.713, 285.446, -9.8)
part.Anchored = true
part.Parent = game.Workspace

 function MovePart()
local goal = {}
goal.Position = Vector3.new(-27.313, 285.446, -9.8)

local tweenInfo = TweenInfo.new(10)

local tween = TweenService:Create(part, tweenInfo, goal)

tween:Play()
 end

workspace.ManholeCover.PartTouch.Touched:connect(MovePart)

2 comments

0

Do you mean that it would fire the action when a player touches it (instead of any normal part)?

0

yes

2 answers

Debugging time!

  • workspace is deprecated, use game.Workspace instead.

Now, you would use GetPlayers() to acquire certain player(s) like this:

plr = game.Players:GetPlayers("Player1")
script.Parent.Touched:connect(function()
	if script.Parent:FindFirstChild("Humanoid") ~= nil then
		local human = script.Parent:FindFirstChild("Humanoid")
		if human.Parent == plr.Character then
			-- Code here
		end
	end
end)

3 comments

0

I use 'workspace' it still works

0

But using deprecated code can cause problems. Example you use :connect when it's :Connect. I tried using :connect and I get errors that "connect is not RBXScriptSignal" or something.

0

tells me, "attempt to connect failed: Passed value is not a function" and "attempt to call a nil value"

This discussion is preserved as it was. New answers, comments, and votes are closed.