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
local giveTool = game.ReplicatedStorage.givetool.Value while true do map = game.ReplicatedStorage.Maps.map1:Clone() map.Parent = game.Workspace giveTool = 1 -- Changes the value wait(120) -- round time is 2 mins map:Destroy() map = game.ReplicatedStorage.Maps.map2:Clone map.Parent = game.Workspace giveTool = 0 wait(120) map:Destroy() end
ToolGiver script: it is a script in workspace:
game.ReplicatedStorage.givetool.Changed:Connect(function() local tool = game.Lighting.tools.tool1:Clone() tool.Parent = game.Players.LocalPlayer.Backpack 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.
function givePlayersTool() local players = game.Players:GetChildren() for i, v in pairs(players) do local clone = game.Lighting.tools.tool1:Clone() clone.Parent = v.Backpack end end while true do givePlayersTool() map = game.ReplicatedStorage.Maps.map1:Clone() map.Parent = game.Workspace wait(120) map:Destroy() map = game.ReplicatedStorage.Maps.map2:Clone map.Parent = game.Workspace givePlayersTool() wait(120) map:Destroy() 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:
local giveTool = game.ReplicatedStorage.givetool.Value while true do map = game.ReplicatedStorage.Maps.map1:Clone() map.Parent = game.Workspace giveTool = 1 game.ReplicatedStorage.GiveToolEvent:FireAllClients(giveTool) wait(120) map:Destroy() map = game.ReplicatedStorage.Maps.map2:Clone() map.Parent = game.Workspace giveTool = 0 wait(120) map:Destroy() end
LocalScript:
game.ReplicatedStorage.ToolGivingEvent.OnClientEvent:Connect(function(giveTool) local player = game:GetService("Players").LocalPlayer local Tool = game.Lighting.tools:FindFirstChild("tool"..giveTool):Clone() Tool.Parent = player.Backpack end)
Let me know if that works!