Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why is my player not respawning remot event in tool?

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?

2 comments

0

What’s a normal script?

0

serverscript ... sorry

2 answers

✓ Accepted answer

###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)

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.

8 comments

0

The first script is a local script and plr = the target so? Otherwise how i need to do it?

0

Here I'll update the post and show you what you'll need to add/change.

0

But plr is already the target

0

I updated it but it respawns yourself?

0

I don't understand exactly what you want this script to do.

0

To respawn load the player that's targeted

0

Your script is wrong.

0

What I wrote makes more sense before op edited the post tbh.

This discussion is preserved as it was. New answers, comments, and votes are closed.