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

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

Asked by
Echtic 128
5 years ago
Edited 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 starter GUI, the first script is local and the other one is not, the game is not filtering enabled.The non local script is marked as 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 -- you can try with userid instead, so it works regardless when you change of username.
    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.

0
or just place the localscript in startercharacterscripts SulaymanArafat 230 — 5y
0
Your issue was about the LocalScript, which was placed in StarterGui. StarterGui is a "player-like" replication service, which will clone all the children to the PlayerGui, not doing the process again until you rejoin. The player never resets or dies, remember! You should place it in StarterCharacterScripts, inside StarterPlayer! This will run each time character loads then. SulaymanArafat 230 — 5y
0
still the same Echtic 128 — 5y

2 answers

Log in to vote
1
Answered by
SCP774 191
5 years ago

Simple, just move the localscript to StarterCharacterScripts, and the script will work everytime the character respawns.

Ad
Log in to vote
-1
Answered by
IcyMizu 122
5 years ago
Edited 5 years ago

try this for local script

-- LocalScript
game:GetService("ReplicatedStorage"):WaitForChild("ClientRequest")
game.Players.LocalPlayer:connect(function(player)
if player.Name == "iiiAmericanLight" then -- you can try with userid instead, so it works regardless when you change of username.
    event:FireServer()
end)
end)

im not the best scripter im just a beginner but try this for serverscript

-- ServerScript
local event = Instance.new("RemoteEvent"):connect(function(event)
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)
end)

if this doesnt work im srry im not that good at scripting yet

0
What the?! SulaymanArafat 230 — 5y

Answer this question