Why this is no working?

Hello, I’m creating a button that respawns the player, and it is no working

script.Parent.MouseButton1Click:Connect(function()
	script.Parent.Parent.Parent.Parent.Parent.Parent:LoadCharacter()
end)

This is the script, but is no working, can someone help me?

1 Like

Do it by remote event.
Clients cannot respawn the player. Only the server can.

You can make a Remote event And do it like

local RemoteEvent = yourRemoteEvent --for eg game.ReplicatedStorage.RespawnEvent
script.Parent.MouseButton1Click:Connect(function()
RemoteEvent:Fire()
end)

and in other script in ServerScriptService

local RemoteEvent = yourRemoteEvent --for eg game.ReplicatedStorage.RespawnEvent

RemoteEvent.OnServerEvent:Connect(function(player) --player comes as default
    player:LoadCharacter()
end)

THIS CODE IS LOCAL FOR EXPLANTION

Oh, It doesn’t work, this is a image of the output image

Remote events use :FireServer() not :Fire()
Thus you would do

RemoteEvent:FireServer()

Use FireServer instead of Fire.

Now the output say this :confused: image

It has to be fired on a local script and recieved on a server script

1 Like

For it to work you need to add a remote event.

He added a remote event.
As what I said way before this.

Remote Events are used to communicate between the client and the server, not between 2 server scripts. To communicate between 2 server scripts, use a BindableEvent:

Ohhhh, thanks!
I’m starting with lua…

Oh, I just now saw your reply, sorry about that! I’m new here and just trying to contribute however I can.

1 Like