What do you want to achieve?
i want to make a “G” to deploy landmine
What is the issue?
i dunno how to make if my character touched the landmine it dosnt explode and it will only trigger if character humanoid touched it and not in my team
UIS.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.G then
local clone = rf.Mine.Landmine:Clone()
clone.Parent = workspace
clone.Position = script.Parent.Handle.Position
clone.Anchored = false
clone.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") and not Character then
clone.Anchored = true
local explode = Instance.new("Explosion")
explode.Parent = clone
explode.Position = clone.Position
end
end)
end
end)```
not a full script
parent = script.parent
(Tool)
So this assumes that your Character variable used in your example belongs to the player who set the landmine and that you are using tradition Roblox Team objects and that it only needs to explode if a Player touches it. If you need it to explode on NPCs and stuff like that it won’t be too difficult to adapt it…
UIS.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.G then
local clone = rf.Mine.Landmine:Clone()
clone.Parent = workspace
clone.Position = script.Parent.Handle.Position
clone.Anchored = false
local hit_signal = nil; -- Set up a variable to hold our touch signal listener so we can disconnect it later.
hit_signal = clone.Touched:Connect(function(hit)
local owner = game.Players:GetPlayerFromCharacter(Character) -- Get the player who laid the landmine.
local owner_team = owner.Team -- Save this just in case the owner leaves. Might be out dated but better than nothing!
local player = game.Players:GetPlayerFromCharacter(hit.Parent) -- Get the player who touched the mine, if they exist.
if player and ((not owner and player.Team ~= owner_team) or player.Team ~= owner.Team) then
clone.Anchored = true
local explode = Instance.new("Explosion")
explode.Parent = clone
explode.Position = clone.Position
hit_signal:Disconnect() -- Disconnect our touch signal listener so we don't explode more than once.
end
end)
end
end)
UIS.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.G then
local clone = rf.Mine.Landmine:Clone()
clone.Parent = game.Workspace -- <---- Here
clone.Position = script.Parent.Handle.Position
clone.Anchored = false
local hit_signal = nil; -- Set up a variable to hold our touch signal listener so we can disconnect it later.
hit_signal = clone.Touched:Connect(function(hit)
local owner = game.Players:GetPlayerFromCharacter(Character) -- Get the player who laid the landmine.
local owner_team = owner.Team -- Save this just in case the owner leaves. Might be out dated but better than nothing!
local player = game.Players:GetPlayerFromCharacter(hit.Parent) -- Get the player who touched the mine, if they exist.
if player and ((not owner and player.Team ~= owner_team) or player.Team ~= owner.Team) then
clone.Anchored = true
local explode = Instance.new("Explosion")
explode.Parent = clone
explode.Position = clone.Position
hit_signal:Disconnect() -- Disconnect our touch signal listener so we don't explode more than once.
end
end)
end
end)