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

How to clone tools into a player backpack?

Asked by 5 years ago

Hello Everyone

I've been trying to create code where after an intermission time, a sword will be given to the player.

Here is a regular script (Not LocalScript) of the game loop that I made

01Main = require(game.Workspace.ModuleScripts.Main)
02local status = game.ReplicatedStorage:WaitForChild("Status")
03local intermissionTime = 60
04local roundTime = 120
05local players = game.Players:GetPlayers()
06local playerService = game.Players
07local Number = intermissionTime
08 
09local sword = game.ServerStorage.Swords.BasicSword
10 
11while true do
12    for i = 1, intermissionTime, 1 do -- Countdown for intermission time
13        status.Value = "INTERMISSION (" .. Number .. ")"
14        wait(1)
15        Number = Number - 1
View all 36 lines...

When I run it, The tool won't show up after the intermission time is over, but no errors are shown in the output. Can someone please tell me what is happening and how to fix this so it will show up?

Thanks in advance :)

1
from my experience you cant get tools from server storage maybe thats the problem? if it is try putting it in something else 3wdo 198 — 5y

3 answers

Log in to vote
0
Answered by 5 years ago

I'm not sure if this will solve your problem, but try putting the sword in replicated storage, that is what I usually do. I also saw that in line 22 for the paramater of the function you put player with a capital P. In line 23 however, you put player with a lower case p.

0
I put the sword folder in replicated storage but that also didn't work. Thanks anyway :) JustAnotherGaming 48 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

I already see the issue here. When the games starts, it clears something from the ServerStorage, and it doesn't detect the item being in the ServerStorage, to prevent that from happening, you'd declare the variable by placing a duplicate of the Sword in ReplicatedStorage, but, keep the normal Sword in ServerStorage, write this code:

1local sword = game.ServerStorage.Swords.BasicSword or game.ReplicatedStorage.Swords.BasicSword

That way, if the sword doesn't happen to be in ServerStorage, it automatically searches in the ReplicatedStorage.

0
When I Tried it, it still did not work, thanks anyway :) JustAnotherGaming 48 — 5y
Log in to vote
0
Answered by 5 years ago

Here you go!

01local time = 0 
02    local plrs = game.Players:GetChildren()
03            local plr = plrs math.random(1,#plrs)
04            for p = 1,#plrs do
05                time = 120
06                game.ReplicatedStorage.Sword.Parent = plrs[p].Backpack
07                repeat
08                    time = time - 1
09                    wait(1)
10                    until time == 0
0
When I tried it, it still didn't work, thanks anyway :) JustAnotherGaming 48 — 5y

Answer this question