I am making a small simulator, and I have come across a massive issue. On my main account, everything works fine. But on any other account, you have to exit and enter the swinging area over and over to get any power increase.
Main account (account issue, device doesn’t matter):
(sorry for bad quality, didn’t feel like opening OBS lol)
My testing ACC (device doesn’t matter still):
My friend also has this issue on his account. Not sure what’s up…
Here’s the code I made for it (was in a rush):
local players = game:FindFirstChild("Players")
local par = script.Parent
local face = par.Base.Face.WorldPosition
local spot = par.Base.Pos.WorldCFrame
local prompt = par.Base.Holder.Prompt
local anims = game.ServerStorage.Animations
local hit = par.Hit
local swingAnim = anims.Swings.Default
local pow = par:GetAttribute("Power")
local requiredGUI = par.Base.Info.InfoGUI
local requiredPower = par:GetAttribute("PowerNeeded")
requiredGUI.Amt.Text = tostring(requiredPower)
local originalSwingTime = 0.56
function PlaySound(sound: Sound)
local s = sound:Clone()
s.Parent = par.Base
s.Ended:Connect(function() s:Destroy() end)
s:Play()
end
function OnTrigger(player: Player)
local char = player.Character or nil
local bat = char:FindFirstChild("Bat")
local t = player:WaitForChild("Training") :: BoolValue
if t.Value == false and bat then
local barrel = bat:FindFirstChild("Barrel")
if barrel then
local power = player:WaitForChild("leaderstats"):WaitForChild("Power") :: NumberValue
if power then
if power.Value >= requiredPower then
local training = true
if char then
t.Value = true
local exitGui = player.PlayerGui.Exit
local modifier = 0
local mul = player:WaitForChild("batMul") :: NumberValue
modifier += mul.Value
local mul2 = player:WaitForChild("Modifier") :: NumberValue
modifier += mul2.Value
modifier = math.clamp(modifier,1,math.huge)
if modifier == 2 then
modifier = 1
end
char.PrimaryPart.Anchored = true
local hum = char:FindFirstChildOfClass("Humanoid")
hum.AutoRotate = false
local anim = hum:LoadAnimation(swingAnim)
anim:Play()
local last = tick()
local cooldown = false
local y = char.PrimaryPart.CFrame.Y
exitGui.ExitEvent.OnServerEvent:Connect(function(plr)
if plr == player then
training = false
t.Value = false
hum.AutoRotate = true
char.PrimaryPart.Anchored = false
anim:Stop()
anim:Destroy()
exitGui.Enabled = false
return
end
end)
exitGui.Enabled = true
repeat
local nx,ny,nz = CFrame.lookAt(char.PrimaryPart.Position,face):ToOrientation()
char.PrimaryPart.CFrame = CFrame.new(Vector3.new(spot.Position.X,y,spot.Position.Z))*CFrame.Angles(0,ny,0)
local distance = (barrel.Position-hit.Position).Magnitude
if cooldown == false and distance < 1.5 then
cooldown = true
power.Value += pow*modifier
PlaySound(script.Swing)
task.wait(0.1)
cooldown = false
end
task.wait()
until training == false
end
end
end
end
end
end
function AddGUI(player: Player)
local gui = requiredGUI:Clone()
gui.Obj.Value = par
gui.Parent = player.PlayerGui
gui.Trigger.OnServerEvent:Connect(OnTrigger)
gui.Enabled = true
end
for i,plr in pairs(players:GetChildren()) do
if plr:IsA("Player") then
AddGUI(plr)
end
end
players.PlayerAdded:Connect(function(plr)
AddGUI(plr)
end)
prompt.Triggered:Connect(OnTrigger)
(no errors either btw!)