Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why isn't my script creating the "ball" ?

local Player = game.Players.LocalPlayer local Character = Player.Character or Player.CharacterAdded:Wait() wait(1) local Humanoid = Character.Humanoid or Character:WaitForChild("Humanoid") local mouse = Player:GetMouse() local ok = 0

function charge() if ok == 0 then ok = 40 local anim = Instance.new("Animation") anim.AnimationId = "rbxassetid://4364880762" local animationtrack = Humanoid:LoadAnimation(anim) animationtrack:Play() wait(0.2) local ball = Instance.new("Part") ball.Shape = "Ball" ball.CFrame = Humanoid.RightArm.CFrame * CFrame.new(0,-0.9,0) ball.Size = Vector3.new(1, 1, 1) ball.Parent = game.Workspace ball.Material = "Neon" ball.BrickColor = BrickColor.new("Blue") ball.Transparency = 0 ok = 3 end end

mouse.KeyDown:Connect(function(key) if key == "q" then charge() end end)

1 comment

2

Bro put your code in a code block so it is easier to understand

1 answer

Don't use

mouse.KeyDown:Connect(function(key)
 if key == "q" then 
   charge() 
    end 
end)

You can use it, but UIS, or User input service is alot more efficient.

Here's an example of how UIS looks like:

local UIS = game:GetService('UserInputService')

UIS.InputBegan:connect(function(key,istyping)
  if key.KeyCode == Enum.KeyCode.Q then
         -- do whatever here
    end
end)

Also, next time when posting your issue, please, put your line of code in a code block!

2 comments

0

This doesn't answer his question.

0

You don't avoid KeyDown because of "inefficiency", you avoid it because it is deprecated. Please don't give anymore bad answers I'm running out of downvotes downvoting other poor quality posts.

This discussion is preserved as it was. New answers, comments, and votes are closed.