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

Why is my player not respawning remot event in tool?

Asked by 5 years ago
Edited 5 years ago

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?

0
What’s a normal script? User#19524 175 — 5y
0
serverscript ... sorry MaxDev_BE 55 — 5y

2 answers

Log in to vote
0
Answered by 5 years ago

The problem with your script is you’re passing the 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.

LocalScript

local plr = game:GetService"Players".LocalPlayer
local mouse = plr:GetMouse()

script.Parent.RespawnPlr:FireServer(mouse.Target.Parent)

Server Script

script.Parent.OnServerEvent:Connect(function(plr, target)
    local plr = plr.Parent:GetPlayerFromCharacter(target)

    if plr then
        plr:LoadCharacter()
    end
end)
Ad
Log in to vote
-1
Answered by 5 years ago
Edited 5 years ago

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.

0
The first script is a local script and plr = the target so? Otherwise how i need to do it? MaxDev_BE 55 — 5y
0
Here I'll update the post and show you what you'll need to add/change. Optimalpokemon123 37 — 5y
0
But plr is already the target MaxDev_BE 55 — 5y
0
I updated it but it respawns yourself? MaxDev_BE 55 — 5y
View all comments (4 more)
0
I don't understand exactly what you want this script to do. Optimalpokemon123 37 — 5y
0
To respawn load the player that's targeted MaxDev_BE 55 — 5y
0
Your script is wrong. User#19524 175 — 5y
0
What I wrote makes more sense before op edited the post tbh. Optimalpokemon123 37 — 5y

Answer this question