Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 6 years ago

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)
0
Do you mean that it would fire the action when a player touches it (instead of any normal part)? User#20388 0 — 6y
0
yes lolkid007 43 — 6y

2 answers

Log in to vote
0
Answered by 6 years ago

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)
0
I use 'workspace' it still works hellmatic 1523 — 6y
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. User#19524 175 — 6y
0
tells me, "attempt to connect failed: Passed value is not a function" and "attempt to call a nil value" lolkid007 43 — 6y
Ad
Log in to vote
0
Answered by 6 years ago

print("Testing")

0
solved all my problems lolkid007 43 — 6y

Answer this question