Do any of you know how to fix this tool giving script? There is a localscript inside a button that sets a stringvalue inside the player to the tool's name. A serverscript then searches serverstorage for a tool the has a name that matches the stringvalue. It works in studio but not game.
The local script inside the button
script.Parent.MouseButton1Click:Connect(function()
game.Players.LocalPlayer.EquippedTool.Value = script.Parent.Name
script.Parent.BorderSizePixel = 5
script.Parent.ZIndex = 2
for i, image in pairs(script.Parent.Parent:GetChildren()) do
if image.Name ~= script.Parent.Name then
image.ZIndex = 1
image.BorderColor3 = Color3.new(0,0,0)
image.BorderSizePixel = 1
end
end
script.Parent.BorderColor3 = Color3.new(255,0,0)
end)
Script in serverscriptservice (SpawnEvent fired by another local script in buttton)
game:GetService("ReplicatedStorage"):WaitForChild("SpawnEvent").OnServerEvent:Connect(function(player)
if player.EquippedPrimary.Value == "" then
-- Give them a basic tool
else
local primary = game.ServerStorage[player.EquippedTool.Value]:Clone()
primary.Parent = player.Backpack
end
end)
