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

How do I make a script that gives player a tool?

Asked by 5 years ago

I making a round system that gives the player a tool when the round starts heres my code:

this is the round script: it is a script in ServerSciptService

01local giveTool = game.ReplicatedStorage.givetool.Value
02 
03while true do
04 
05    map = game.ReplicatedStorage.Maps.map1:Clone()
06    map.Parent = game.Workspace
07 
08    giveTool = 1 -- Changes the value  
09 
10    wait(120) -- round time is 2 mins
11    map:Destroy()
12 
13    map = game.ReplicatedStorage.Maps.map2:Clone
14    map.Parent = game.Workspace
15 
View all 21 lines...

ToolGiver script: it is a script in workspace:

1game.ReplicatedStorage.givetool.Changed:Connect(function()
2 
3    local tool = game.Lighting.tools.tool1:Clone()
4 
5    tool.Parent = game.Players.LocalPlayer.Backpack
6 
7end)

What am i doing wrong? it wont give me the tool!

2 answers

Log in to vote
0
Answered by
Raccoonyz 1092 Donator Moderation Voter
5 years ago

Hi there, Server scripts cannot use LocalPlayer. Also, if you tried to add the tool locally it'd only show for the local player. You also don't need to use multiple scripts. Here's an example of what you can do.

01function givePlayersTool()
02local players = game.Players:GetChildren()
03for i, v in pairs(players) do
04local clone =  game.Lighting.tools.tool1:Clone()
05clone.Parent = v.Backpack
06end
07end
08while true do
09    givePlayersTool()
10    map = game.ReplicatedStorage.Maps.map1:Clone()
11    map.Parent = game.Workspace
12    wait(120)
13    map:Destroy()
14    map = game.ReplicatedStorage.Maps.map2:Clone
15    map.Parent = game.Workspace
16    givePlayersTool()
17    wait(120)
18    map:Destroy()
19end
0
If i wanted to delete the tool would i just put v.Backpack.tool:Destroy? Encryptal 0 — 5y
0
Yes. Raccoonyz 1092 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

HI! So the problem i noticed first was that you are calling the localplayer from a server script and not a local script. I recommend using a remote event and firing to all clients where the local script would be in the starterplayerscripts...

ServerScript:

01local giveTool = game.ReplicatedStorage.givetool.Value
02 
03while true do
04    map = game.ReplicatedStorage.Maps.map1:Clone()
05    map.Parent = game.Workspace
06    giveTool = 1
07game.ReplicatedStorage.GiveToolEvent:FireAllClients(giveTool)
08    wait(120)
09    map:Destroy()
10    map = game.ReplicatedStorage.Maps.map2:Clone()
11    map.Parent = game.Workspace
12    giveTool = 0
13    wait(120)
14    map:Destroy()
15end

LocalScript:

1game.ReplicatedStorage.ToolGivingEvent.OnClientEvent:Connect(function(giveTool)
2    local player = game:GetService("Players").LocalPlayer
3    local Tool = game.Lighting.tools:FindFirstChild("tool"..giveTool):Clone()
4    Tool.Parent = player.Backpack
5end)

Let me know if that works!

0
Where would i put the local script? Thanks for answering btw! Encryptal 0 — 5y
0
Put it in starter playerscripts. In the explorer, go to the very botton then open the drop down for StarterPlayer, then add a localscript to starterplayer scripts FishslayerX 8 — 5y

Answer this question