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

Character is supposed to respawn/load when "f" is pressed. Help?

Asked by 5 years ago

What it is supposed to do is respawn/load your character when you press "f." I haven't scripted in a month and I kind of forgot some stuff :') So here it is.

script.Parent = game.StarterGui
wait()
local k = game.Players.LocalPlayer:GetMouse()
k.KeyDown:connect(function(a)
if a:lower() == "f" then
local c = game.Players.LocalPlayer.Character
if c then
local h = c:findFirstChild("Humanoid")
if h then h:LoadCharacter()
end
end
end
end)

I'm not sure what to do so can someone help me?

0
first of all use UserInputService Enum.KeyCode then you need a remote event then u reload your char from there WillBe_Stoped 71 — 5y
0
Server Script WillBe_Stoped 71 — 5y
0
Okay thanks that helped User#23357 0 — 5y
0
What kind of advice is that? DeceptiveCaster 3761 — 5y
0
use userinputservice LoganboyInCO 150 — 5y

1 answer

Log in to vote
1
Answered by 5 years ago

If you still need help then I have created a script for this.

First, you would need to create a RemoteEvent and place that inside of ReplicatedStorage.

Then, create a LocalScript and place that inside of StarterGui with the following code inside:

LocalScript

local event = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent")
local UIS = game:GetService("UserInputService")

UIS.InputBegan:Connect(function(key, gpe)
    if key.KeyCode == Enum.KeyCode.F and not gpe then --if player pressed the key F it would trigger this 
        event:FireServer() -- fire the server so it could reload the player
    end
end)

The code will check if the player pressed the F key and it would fire the RemoteEvent

Lastly, create a Script and place that inside of ServerScriptService with the following code inside:

Server Script

local event = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent")

event.OnServerEvent:Connect(function(player) -- when event is fired
    player:LoadCharacter() -- respawn the player
end)

The code will fire after the player has pressed the F. key. LoadCharacter() will reload the player's character making it respawn.

Ad

Answer this question