i am making a Seat
platform that prints "moving" when you press "w" while sitting on it.
the problem is, when i set the parameter for my Touched event, it was the character instead of the localplayer. am i able to somehow get it?
here is my code:
local sitting = false local seat = script.Parent local force = seat.BodyForce local gyro = seat.BodyGyro local pos = seat.BodyPosition local occupant = seat.Occupant force.Force = Vector3.new(0,0,0) pos.MaxForce = Vector3.new(100000, 100000, 100000) seat.Touched:connect(function(plr) if sitting == false then if occupant ~= seat.Occupant then sitting = true print(plr.Parent.Name) local mouse = plr.Parent:GetMouse() mouse.KeyDown:connect(function(KeyDown) if KeyDown == "w" then print("moving") end end) end end end)
There is something called getplayerfromcharacter, you'd use this to fix your problem:
local Player = game:GetService("Players"):GetPlayerFromCharacter(plr)
This would fix your current problem, but you'd run into another one; you can't get the mouse in a server script if you want it to work as expected online and KeyDown is deprecated: you should MouseButton1Down.
To fix this you should use a remote event: checking where a player touches the seat and when he clicks the mouse on the client then sending a remote event to the server.
Also I'm assuming that is a server script.