I’m making a machine gun which when you sit down, clones a “control” script into your character. However, if you get up and sit back down on the machine gun, it doesn’t clone again.
script.Parent.Changed:Connect(function()
print("hiii")
local a = script.Parent.Occupant
local b = game.Players:FindFirstChild(a.Parent.Name)
if b~= nil then
print("NOOOO")
if a.Parent:findFirstChild("control") == nil then
local g=script:WaitForChild("control"):Clone()
print("IT WORKED")
g.Value.Value=script.Parent.Parent.Parent
g.Parent=b.Character
g.Disabled=false
occupier = b
end
end
end)```
From what I got from the information you gave us, it’s a local script so I tried my best to fix it. When you parent the clone to the character you already had the character as a variable so you didn’t need to put b.Character, then there’s a undefined variable " occupier " so I made it a variable itself.
script.Parent.Changed:Connect(function()
print("hiii")
local a = game:GetService("Players").LocalPlayer
local b = a.Character or a.CharacterAdded:Wait()
if b then
print("NOOOO")
if not b.Parent:FindFirstChild("control") then
local g = script:WaitForChild("control"):Clone()
print("IT WORKED")
g.Value.Value = script.Parent.Parent.Parent
g.Parent= b
g.Disabled = false
local occupier = b
end
end
end)
Sorry I like spacing my code out to view it better.
script.Parent.Changed:Connect(function()
print("hiii")
local a = game:GetService("Players").LocalPlayer
local b = a.Character or a.CharacterAdded:Wait()
local g
if b then
if script.Parent == b then
print("NOOOO")
g = script:WaitForChild("control"):Clone()
print("IT WORKED")
g.Value.Value = script.Parent.Parent.Parent
g.Parent= b
g.Disabled = false
local occupier = b
elseif script.Parent == workspace then-- change this to the parent the tool going to be when its not in the character
if g then
g:Remove()
end
end
end
end)
im pretty sure I said several times its not a tool nor is it a local script, the “control” is a local script that gets cloned into the player when they sit on the machine gun and it is what allows them to opperate it.
Because this is false. In the first time using whatever this is, there’s no Instance called “control” in the character, and then it’s cloned and added in the character. When you use for the second time and check if there is not a child called “control”, it’ll be false because there is.