So, here's the explanation to my script: Basically their will be 4 invisible parts that will cover a certain area and the only way to get in is to walk through those parts causing a touched event to occur which will see if you have a sword and if not, give you a sword plus Global Variable in your player to mimic if you have one of not. This script is having problems when a tool or hat touched the part causing it so say "Humanoid is not a valid member of Hat". Is their a better way to perform my script or do I have to work out the bugs?
script: (Not a LocalScript)
db = false
script.Parent.Touched:connect(function(Hit)
local Character = Hit.Parent
local Player = game.Players:GetPlayerFromCharacter(Character)
if Hit.ClassName == "Part" and Character and Character.Humanoid and Character:FindFirstChild("SwordStatus") == nil then
if db == false then db = true
local Has = Instance.new("BoolValue", Character)
Has.Name = "SwordStatus"
Has.Value = false
if Character.SwordStatus.Value == false then
local Getting = game.ReplicatedStorage.LinkedSword:Clone()
Getting.Parent = Player.Backpack
Hit.Parent.SwordStatus.Value = true
wait(0.5)
db = false
end
end
elseif Hit.ClassName == "Part" and Character and Character.Humanoid and Character:FindFirstChild("SwordStatus") ~= nil then
if db == false then db = true
if Character.SwordStatus.Value == true then
local FindSwordB = Player.Backpack:FindFirstChild("LinkedSword")
local FindSwordPlr = Character:FindFirstChild("LinkedSword")
if FindSwordB ~= nil and FindSwordPlr == nil then
FindSwordB:remove()
wait(0.5)
db = false
elseif FindSwordB == nil and FindSwordPlr ~= nil then
FindSwordPlr:remove()
wait(0.5)
db = false
end
end
end
elseif Hit.ClassName == "Hat" then
print("")
elseif Hit.ClassName == "Tool" then
print("")
end
end)
