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

Scripts only work the first time a player joins the server, how do i fix that?

Asked by
Echtic 128
5 years ago

My scripts don't work after the character respawns, even after rejoining the game they still don't work.

The scripts work as intended but only first time character joins the game, they are both inside the StarterCharacterScripts, the first script is local and the other one is not, the game is not filtering enabled.The non local script is named a server script.

Here is the first script:

-- LocalScript
local event = game:GetService("ReplicatedStorage"):WaitForChild("ClientRequest")
local player = game.Players.LocalPlayer
if player.Name == "iiiAmericanLight" then 
    event:FireServer()
end

And now the second one:

-- ServerScript
local event = Instance.new("RemoteEvent")
event.Parent = game:GetService("ReplicatedStorage")
event.Name = "ClientRequest"

event.OnServerEvent:Connect(function(player)
    local swr = game:GetService("ServerStorage"):WaitForChild("Meliodas Sword")
    local pfr = game:GetService("ServerStorage"):WaitForChild("PurgatoryFlame")

    local sw = swr:Clone()
    local pf = pfr:Clone()

    sw.Parent = player.Backpack
    pf.Parent = player.Backpack
end)

P.S there is nothing in the output. I would really appreciate some help with this.

1 answer

Log in to vote
0
Answered by
chomboghai 2044 Moderation Voter Community Moderator
5 years ago

The LocalScripts you are using will only run once. Instead, try using the CharacterAdded event from the Players service, which fires every time a player spawns or respawns.

0
? chomboghai 2044 — 5y
0
ChractedAdded is not about every time a player spawn... SwingingMelons -18 — 5y
0
Yes it is. Description: Fired when a player's character spawns or respawns. - Wiki https://wiki.roblox.com/index.php?title=API:Class/Player/CharacterAdded iiDayzie_Dreams 32 — 5y
Ad

Answer this question