Hello everyone. Im trying to make an AA gun. For that i need to clone a localscript from the model to the playerscritps, but tis not working.
The script:
wait(3)
local model = game.Workspace.AmericanBase.Cannons["Anti-Air1"]
local seat = model.Seat
local s = script.Parent.AA1
seat.Touched:Connect(function(touch)
local c = touch.Parent:FindFirstChild("Humanoid")
if c then
wait(0.5)
local player = game.Players:GetPlayerFromCharacter(c.Parent)
print(player.Name)
if player == true then
if seat.Occupant ~= nil then
print (seat.Occupant)
local cl = s:Clone()
local ps = player:FindFirstChild("PlayerScripts")
cl.Parent = ps
cl.Disabled = false
end
end
end
end)
Player == true will NEVER be true since the Player is a Object More specificaly a Userdata not a boolean. Instead do if Player then Since everything other than nil and false evaluate to true
wait(3)
local model = game.Workspace.AmericanBase.Cannons["Anti-Air1"]
local seat = model.Seat
local s = script.Parent.AA1
seat.Touched:Connect(function(touch)
local c = touch.Parent:FindFirstChild("Humanoid")
if c then
wait(0.5)
local player = game.Players:GetPlayerFromCharacter(c.Parent)
print(player.Name .."PlayerName")
if seat.Occupant ~= nil then
print (seat.Occupant .."Occupant")
local cl = s:Clone()
local ps = player:FindFirstChild("PlayerScripts")
cl.Parent = ps
cl.Disabled = false
end
end
end)
yes seat.Occupant is a object value and can’t be concatenated turn it to a string tostring(seat.Occupant) or seat.Occupant.Name (Which would return humanoid) You need to do .Parent to get the player.
wait(3)
local model = game.Workspace.AmericanBase.Cannons["Anti-Air1"]
local seat = model.Seat
local s = script.Parent.AA1
seat.Touched:Connect(function(touch)
local c = touch.Parent:FindFirstChild("Humanoid")
if c then
wait(0.5)
local player = game.Players:GetPlayerFromCharacter(c.Parent)
print(player.Name .."PlayerName")
if seat.Occupant ~= nil then
print (tostring(seat.Occupant).."Occupant")
local cl = s:Clone()
local ps = player:FindFirstChild("PlayerScripts")
cl.Parent = ps
cl.Disabled = false
end
end
end)
wait(3)
local model = game.Workspace.AmericanBase.Cannons["Anti-Air1"]
local seat = model.Seat
local s = script.Parent.AA1
seat.Touched:Connect(function(touch)
local c = touch.Parent:FindFirstChild("Humanoid")
if c then
wait(0.5)
local player = game.Players:GetPlayerFromCharacter(c.Parent)
print(player.Name .."PlayerName")
if player ~= nil then
if seat.Occupant ~= nil then
print (tostring(seat.Occupant) .."Occupant")
local cl = s:Clone()
local ps = player:FindFirstChild("PlayerScripts")
cl.Parent = ps
cl.Disabled = false
end
end
end
end)
wait(3)
local model = game.Workspace.AmericanBase.Cannons["Anti-Air1"]
local seat = model.Seat
local s = script.Parent.AA1
seat.Touched:Connect(function(touch)
local c = touch.Parent:FindFirstChild("Humanoid")
if c then
wait(0.5)
local player = game.Players:GetPlayerFromCharacter(c.Parent)
print(player.Name .."PlayerName")
if player ~= nil then
if seat.Occupant ~= nil then
print (tostring(seat.Occupant.Parent.Name) .."Occupant")
local cl = s:Clone()
local ps = player:FindFirstChild("PlayerScripts")
cl.Parent = ps
cl.Disabled = false
end
end
end
end)