i’ve been trying to make it where if my tool touches part it will add a value to Storage
function onTouched(part,Players)
local h = part.Parent:FindFirstChild("Humanoid")
if (h~=nil) then
local thisplr = game.StarterPack["Basic Net"].Handle
if (thisplr~=nil) then
local BackPackF = Players.BackpackF
local Storage = BackPackF.Storage
local MaxStorage = BackPackF.MaxStorage
Storage.Value = Storage.Value +1
wait(.2)
script.Parent:remove()
end
end
end
script.Parent.Touched:connect(onTouched)
Is thisplr supposed to be equal to the current player using the tool? If so you can just use game.Players:GetPlayerFromCharacter(h.Parent). That will get the Player from the Character found.
Where is the Storage located? IS BackPackF located in the Player? So whenever the player hits the part, they “Collect” it in a way?
Also, I believe Players is going to be nil as the Touched only outputs the part touched and not Players but I may be wrong I have never seen that before.
Edit: Where is this script located? Is this under the part being collected or under the tool?
local BasicNet = game.StarterPack["Basic Net"].Handle
local Bread = game.Workspace.Bread
script.Parent.Equipped:Connect(function(Mouse)
Mouse.Button1Down:Connect(function()
Swing = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Parent.Swing)
Swing:Play()
if Swing:Play()then
Bread.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild(BasicNet) then
game.Players.LocalPlayer.BackpackF.Storage.Value = game.Players.LocalPlayer.BackpackF.Storage.Value + 1
end
end)
end
end)
end)
script.Parent.Unequipped:Connect(function()
Swing:Stop()
end)
I don’t think you need if Swing:Play() then you can just use Bread.Touched. Here is an idea though for you that can probably make this entire thing a lot easier. Create a folder within Workspace that holds all the bread in it. Create a new script under ServerScriptService and in that script do this. Use a For Loop to loop through the folder holding your bread. This will look a little like this
local bread = game.Workspace:WaitForChild("Bread")
for i,bread in pairs(bread:GetChildren()) do
end
You can then use the .touched with the bread within this loop
for i,bread in pairs(bread:GetChildren()) do
bread.Touched:connect(function(touched)
end)
end
Then from there, you should be able to receive the tool that touched it, make sure it is a tool and not a player walking on the bread. From the Tool, you can receive the player, and with the player, you can change the stat within the Player’s backpack. Changing these important values on the client is dangerous and assuming you want the server to see how much bread the player has you should be changing the value on the server.
Over in the LocalScript located under the tool you can use
local playerSwinging = false
script.Parent.Equipped:Connect(function(Mouse)
Mouse.Button1Down:Connect(function()
if not playerSwinging then
playerSwinging = true
Swing = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Parent.Swing)
Swing:Play()
Swing.Stopped:wait()
playerSwinging = false
end
end)
end)
This will play the animation and also has the debounce. Id check debounces out too, those are pretty important