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
01 | local giveTool = game.ReplicatedStorage.givetool.Value |
02 |
03 | while true do |
04 |
05 | map = game.ReplicatedStorage.Maps.map 1 :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.map 2 :Clone |
14 | map.Parent = game.Workspace |
15 |
ToolGiver script: it is a script in workspace:
1 | game.ReplicatedStorage.givetool.Changed:Connect( function () |
2 |
3 | local tool = game.Lighting.tools.tool 1 :Clone() |
4 |
5 | tool.Parent = game.Players.LocalPlayer.Backpack |
6 |
7 | end ) |
What am i doing wrong? it wont give me the tool!
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.
01 | function givePlayersTool() |
02 | local players = game.Players:GetChildren() |
03 | for i, v in pairs (players) do |
04 | local clone = game.Lighting.tools.tool 1 :Clone() |
05 | clone.Parent = v.Backpack |
06 | end |
07 | end |
08 | while true do |
09 | givePlayersTool() |
10 | map = game.ReplicatedStorage.Maps.map 1 :Clone() |
11 | map.Parent = game.Workspace |
12 | wait( 120 ) |
13 | map:Destroy() |
14 | map = game.ReplicatedStorage.Maps.map 2 :Clone |
15 | map.Parent = game.Workspace |
16 | givePlayersTool() |
17 | wait( 120 ) |
18 | map:Destroy() |
19 | end |
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:
01 | local giveTool = game.ReplicatedStorage.givetool.Value |
02 |
03 | while true do |
04 | map = game.ReplicatedStorage.Maps.map 1 :Clone() |
05 | map.Parent = game.Workspace |
06 | giveTool = 1 |
07 | game.ReplicatedStorage.GiveToolEvent:FireAllClients(giveTool) |
08 | wait( 120 ) |
09 | map:Destroy() |
10 | map = game.ReplicatedStorage.Maps.map 2 :Clone() |
11 | map.Parent = game.Workspace |
12 | giveTool = 0 |
13 | wait( 120 ) |
14 | map:Destroy() |
15 | end |
LocalScript:
1 | game.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 |
5 | end ) |
Let me know if that works!