You can make a tween which makes the force weaker by changing the force to 0,0,0 when it hits something
If I set to 0,0,0 the card will fly?
No that so when it hits something it doesnât just fall down or fly away but should make it so the forces gets weaker and weaker until it doesnât move anymore. (at which point you could despawn the card)
I can help you if you donât know how to do a tween.
Also I want to know why just destroying the card or the body force isnât ideal (so I understand more on what you want it to be like)?
I mean when you destroy the bodyForce the script can break (too many cards inside the workspace you will get some erros and the next cards not gonna have BodyForce)
Why wouldnât it have a body force? The script doesnât cut when another one is called but it finishes it current task of inserting the body force and changing the force. If you make the touch connection after the body force creation then there is no chance of it erroring since it has a body force. (ofc course you would need to disconnect the function when itâs touched something). If you mean you want to keep all the cards even after theyâve hit and dealth damage: It would be bad game design if you didnât make a limit of dropped cards (basically everyone using them and the server lagging so bad because of unused cards. You can add a debris to the card so it destroys after the time you add to the argument)
I got cooldown on the cards. but I will try to change the BodyForce to 0,0,0
How does your current script look?
-----this is the card settings before being fired-----
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvent = ReplicatedStorage:WaitForChild("ShootEvent2")
local random = 1
RemoteEvent.OnServerEvent:Connect(function(player, gunPos, gunOr, mosPos)
local card = ReplicatedStorage.Card:Clone()
card.Parent = game.Workspace
card.Position = gunPos
if random == 1 then
card.BrickColor = BrickColor.new("Bright blue")
print(card.BrickColor)
random = random + 1
elseif random == 2 then
card.BrickColor = BrickColor.new("Bright green")
random = random + 1
print(card.BrickColor)
elseif random == 3 then
card.BrickColor = BrickColor.new("Bright red")
random = random + 1
print(card.BrickColor)
elseif random == 4 then
card.BrickColor = BrickColor.new("Bright yellow")
random = random - 3
print(card.BrickColor)
end
local distance = (mosPos - gunPos).magnitude
local speed = 200
card.CFrame = CFrame.new(gunPos, mosPos)
card.Velocity = card.CFrame.lookVector * speed
local fly = Instance.new("BodyForce",card)
fly.Force = Vector3.new(0, card:GetMass() * workspace.Gravity, 0)
card.Orientation = gunOr + Vector3.new(0, -180, 0)
local attacker = Instance.new("StringValue")
attacker.Name = "Attacker"
attacker.Parent = card
attacker.Value = player.Name
card.Touched:Connect(function()
fly.Force = Vector3.new(0, 0, 0)
end)
end)
local touchConnection = card.Touched:Connect(function()
fly.Force = Vector3.new(0, 0, 0)
touchConnection:Disconnect()
end)
Change the touch to this so it disconnects it because it will no longer be in use after the force is already 0,0,0 (might have a typo)
I think I cant
local touchConnection maybe needs to be inside the function?
what does it say when you hover over the highlighted text?
local touchConnection = nil
touchConnection = card.Touched:Connect(function()
fly.Force = Vector3.new(0, 0, 0)
touchConnection:Disconnect()
end)
change it to this because I referenced it wrong. I think you can also just do without the variable on top but Iâm not sure.
works cool thank you