So i did this in a localscript in the tool
local localplr = game.Players.LocalPlayer local mouse = localplr:GetMouse() local plr = game.Players:FindFirstChild(mouse.Target.Parent.Name) script.Parent.RespawnPlr:FireServer(plr)
but then i got a normal script in the remote event and i did this:
script.Parent.OnServerEvent:Connect(function(plr) plr:LoadCharacter() end)
but that isnt working? Can anyone help?
plr
parameter, when you do not pass it to the FireServer
method of RemoteEvent
. You cannot pass the PlayerMouse
object to a remote, but you can pass its properties, such as Target
and Hit
.local plr = game:GetService"Players".LocalPlayer local mouse = plr:GetMouse() script.Parent.RespawnPlr:FireServer(mouse.Target.Parent)
script.Parent.OnServerEvent:Connect(function(plr, target) local plr = plr.Parent:GetPlayerFromCharacter(target) if plr then plr:LoadCharacter() end end)
Why did you define a localplr? A remote event should send the local player anyway use "plr" instead. A server script also cannot use LocalPlayer or GetMouse() as you need to use these on a localscript.
https://wiki.roblox.com/index.php?title=API:Class/Player/GetMouse
https://wiki.roblox.com/index.php?title=API:Class/Players/LocalPlayer
If you want to fix this you will need to send the mouse information before you fire the event on the localscript so that the server script can use the mouse information.
So you'll want to remove the lines
local localplr = plr.Localplayer local mouse = localplr:GetMouse()
and then you'll want to put in your localscript
local mouse = game.Players.LocalPlayer:GetMouse() local mousetarget = mouse.Target
and then when you fire the remote event you will want to put
script.Parent.RespawnPlr:FireServer(plr,mouse,mousetarget)
as well as in the server script.
script.Parent.OnServerEvent:Connect(function(plr,mouse,mousetarget)
and then you can use the mouse.