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

how do you get the localplayer of a character with a parameter in a serverscript?

Asked by
wookey12 174
6 years ago
Edited 6 years ago

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)

1 answer

Log in to vote
0
Answered by
farrizbb 465 Moderation Voter
6 years ago
Edited 6 years ago

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.

GetPlayer

GetMouse

UserInputService

RemoteEvents

Also I'm assuming that is a server script.

0
Thanks wookey12 174 — 6y
Ad

Answer this question