I am currently making a weapon (tool) for my combat game. In the tool, there is a randomizer value (which is used by 'math.random'
) that when the randomized number reaches a certain number, the perk activates and an effect happens on top of the damaged enemy. The problem is: when I use the tool and the number reaches the exact number, the effect won’t play. I think it has to do with the damage script (server script inside tool) instead of the tool script (Local script that plays anims and other things) because the dmg script is the one that recieves the command.
Here’s the script snippets:
local Debris = game:GetService("Debris")
local TweenService = game:GetService("TweenService")
local PerkValue = script.Parent.PERK_RANDOMIZER_VALUE.Value
script.Parent.Damage.OnServerEvent:Connect(function(Player, Character)
local Humanoid = Character:FindFirstChild("Humanoid")
Humanoid:TakeDamage(10)
if Humanoid.Health <= 0 then
Player.leaderstats.Points.Value = Player.leaderstats.Points.Value + 1
end
if PerkValue == 7 then
print("Function Called!")
local KnockoutStar = game.ReplicatedStorage.Effects.Star:Clone()
local Head = Character:FindFirstChild("Head")
local tweenInfo = TweenInfo.new(0.75, Enum.EasingStyle.Linear)
local Properties = {}
Properties.Size = KnockoutStar.Size * 2
Properties.Transparency = 1
local Tween = TweenService:Create(KnockoutStar, tweenInfo, Properties)
KnockoutStar.CFrame = Head.CFrame:ToWorldSpace(CFrame.new(0, 1.5, 0)) * CFrame.Angles(math.rad(-90), 0, 0)
Tween:Play()
Tween.Completed:Connect(function()
Debris:AddItem(KnockoutStar, 0.7)
end)
end
end)
--ToolScript (The script that assigns a value to the perk number--
local PerkRandomNumber = 1
local PerkValue = script.Parent.PERK_RANDOMIZER_VALUE.Value
PerkValue = PerkRandomNumber
So is there a solution to my problem? Please let me know as soon as possible!