Ok, so I’m trying to make, like, a zone where players hop in and they are given a sword. And the moment they hop out, their sword is gone. Issue is, the sword gets cloned, put to character, and deleted so fast.
I think the problem is in this bit of code:
inMatch.Changed:Connect(function(value)
local sword = game.ServerStorage.ClassicSword:Clone()
if value == true and not character:FindFirstChildWhichIsA("Tool") then
sword.Parent = character
elseif value == false and character:FindFirstChildWhichIsA("Tool") then
character:FindFirstChildWhichIsA("Tool"):Destroy()
end
end)
If you don’t think so, please see everything below. me desperate :<
Entirety of my script:
local TweenService = game:GetService("TweenService")
local zone = script.Parent
local matchTrigger = zone.MatchTrigger
local inSound = matchTrigger.In
local outSound = matchTrigger.Out
local charsIn = {}
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
local inMatch = character:FindFirstChild("InMatch")
inMatch.Changed:Connect(function(value)
local sword = game.ServerStorage.ClassicSword:Clone()
if value == true and not character:FindFirstChildWhichIsA("Tool") then
sword.Parent = character
elseif value == false and character:FindFirstChildWhichIsA("Tool") then
character:FindFirstChildWhichIsA("Tool"):Destroy()
end
end)
matchTrigger.Touched:Connect(function(hit)
local humanoid = hit.Parent:FindFirstChild("Humanoid")
if humanoid and humanoid.RootPart == hit and inMatch.Value == false then
inMatch.Value = true
table.insert(charsIn, character)
for i, v in pairs(zone.BeamBases:GetDescendants()) do
if v.Name == "Top" and #charsIn == 1 then
TweenService:Create(v, TweenInfo.new(1, Enum.EasingStyle.Quint), {Position = Vector3.new(0,3,0)}):Play()
end
end
inSound:Play()
end
end)
matchTrigger.TouchEnded:Connect(function(hit)
local humanoid = hit.Parent:FindFirstChild("Humanoid")
if humanoid and humanoid.RootPart == hit and inMatch.Value == true then
inMatch.Value = false
for i, v in pairs(charsIn) do
table.remove(charsIn, table.find(charsIn, character))
end
for i, v in pairs(zone.BeamBases:GetDescendants()) do
if v.Name == "Top" and #charsIn == 0 then
TweenService:Create(v, TweenInfo.new(1, Enum.EasingStyle.Quint), {Position = Vector3.new(0,0.5,0)}):Play()
end
end
outSound:Play()
end
end)
while wait() do
print(inMatch.Value)
end
end)
end)