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 4 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


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!

2 answers

Log in to vote
0
Answered by
Raccoonyz 1092 Donator Moderation Voter
4 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.

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


0
If i wanted to delete the tool would i just put v.Backpack.tool:Destroy? Encryptal 0 — 4y
0
Yes. Raccoonyz 1092 — 4y
Ad
Log in to vote
0
Answered by 4 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:

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!

0
Where would i put the local script? Thanks for answering btw! Encryptal 0 — 4y
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 — 4y

Answer this question