What do you want to achieve?
I’m trying to make a simple pvp area and remove the tool from the player when they leave and give them a tool when they enter.
What is the issue?
The script keeps on giving the player the tool even though it isn’t supposed to.
What solutions have you tried so far?
I’ve tried messing around with my script.
local Tool = game:GetService("ServerStorage"):WaitForChild("Tools"):WaitForChild("ClassicSword")
local box = script.Parent.HitBox
box.Touched:Connect(function(hit)
if not hit.Parent:FindFirstChild("Humanoid") or hit.Name ~= "HumanoidRootPart" then return end
local hum = hit.Parent:FindFirstChild("Humanoid")
local plr = game:GetService("Players"):GetPlayerFromCharacter(hum.Parent)
local hasTool = hum.Parent:FindFirstChild("ClassicSword") or plr.Backpack:FindFirstChild("ClassicSword")
if hasTool then return end
local tool = Tool:Clone()
tool.Parent = hum.Parent
end)
box.ToucheEnded:Connect(function(hit)
if not hit.Parent:FindFirstChild("Humanoid") or hit.Name ~= "HumanoidRootPart" then return end
local hum = hit.Parent:FindFirstChild("Humanoid")
local plr = game:GetService("Players"):GetPlayerFromCharacter(hum.Parent)
local tool = hum.Parent:FindFirstChild("ClassicSword") or plr.Backpack:FindFirstChild("ClassicSword")
if not tool then return end
tool:Destroy()
end)
(rbxl file removed)
Sorry for late reply, I was away.
This is the entire game I’m making, but anyways you want to walk into the sand pit thing to activate the event.
Ok, so the issue is the way you have the code is when you walk or move it will basically end the touch but then also start it again.
In general .touched is not the best for what ur doing. Your best bet would to use something like raycasting or if u want to keep the touched system have a part or parts which surround the fighting area so if the user touches the box around and has a sword it will be removed.