I made a script that gives the player wood. But sometimes it gives more than one wood. And I know why this is happening, but I have no idea how to fix it.
local rs = game:GetService("ReplicatedStorage")
local rm = rs.ToInv
local plrname = ""
local players = game:GetService("Players")
script.Parent.Touched:connect(function(hit)
script.Parent.Position = Vector3.new(0, 0, 0)
print("touched")
if hit.Parent:FindFirstChild("Humanoid") then
print("human found")
local player = players:GetPlayerFromCharacter(hit.Parent)
if not player then return end
print(player.Name)
rm:FireClient(player, "wood")
wait(60)
script.Parent.Position = Vector3.new(-8.144, 22.073, 166.029)
else
script.Parent.Position = Vector3.new(-8.144, 22.073, 166.029)
end
end)
local rs = game:GetService("ReplicatedStorage")
local rm = rs.ToInv
local inv = script.Parent.InvFrame.Inv
rm.OnClientEvent:Connect(function(item)
print("remote event fired")
if item == "wood" then
for i = 0, 13 do
local istr = tostring(i)
if inv:WaitForChild("Slot" .. istr).item.Value == "" then
inv:WaitForChild("Slot" .. istr).item.Value = "wood"
break
end
end
end
end)
How can I fix this?