Hey, I’m still new to the DevForum so I’ll try not to be annoying. Anyways, I’ve been developing a game for around 2 and a half weeks now, prior to this I’ve had experience with other projects, no other project has gotten this developed though. A MAJOR issue I’ve run into is Instance animations more specifically two separate idle animations, One animation for if the player has the ball and another animation for if the player doesn’t have the ball. Now I’ve tried to the best of my ability to get a rough gist of what I need to do coding wise for it to work. For some reason however, I can’t figure out exactly how to code something like this. I know I need to use an " if " statement but other than that I have ZERO clue what needs to be done. I’m new to coding and don’t really understand how to do it. I’ve tried looking up videos about " if " statements but no video seems to touch on my individual circumstance.
if anyone could point me in the right direction or give me a rough layout on how to code something like this that would be greatly appreciated.
I’ll assume for now that having the ball is denoted by a value in the player (where true = has the ball, false = doesn’t have the ball)
local ballanim = script.ballanim
local noballanim = script.noballanim
game:GetService("Players").PlayerAdded:Connect(function(player)
local hasball = player.hasball.Value
player.CharacterAdded:Connect(function(char)
local hum = char.Humanoid
if hum.MoveDirection == Vector3.new(0,0,0) then -- if idle
if hasball then -- if player has ball
local ballplay = hum.Animator:LoadAnimation(ballanim)
ballplay:Play()
if hum.MoveDirection ~= Vector3.new(0,0,0) then
ballplay:Stop()
end
else
local noballplay = hum.Animator:LoadAnimation(noballanim)
noballplay:Play()
if hum.MoveDirection ~= Vector3.new(0,0,0) then
ballplay:Stop()
end
end
end
end)
end)
This is how I have the script set up as of now, I put each animation ID in “Animation” which is a child of “Idle Animation” the script doesn’t really work
do you know how to make it a member of the player? when you said, “I’ll assume for now that having the ball is denoted by a value in the player (where true = has the ball, false = doesn’t have the ball)”. I have no idea what that means. I know I’m asking a lot but could you help me make “hasball” a member of the player
How does the game know whether or not a play has the ball or not? I can’t help you if you don’t tell me how to check if the player has the ball or not. Also, don’t worry about asking too much, it keeps me occupied because I have nothing better to do
I don’t know if this is helpful or not but a friend of mine did write me a script to where the ball attaches to my leg and it gives me the option to “Kick”. would it be easier for me to add onto that where it would check if the player was touching the ball? (the script is inside of the ball right now) the shoot button doesn’t work but, I’m more worried about an animation playing if the player has the ball. If that doesn’t really help much just tell me exactly what I need to look for and exactly what I need to give you in order to allow you to help me.
local ball = script.Parent
local attached = false
local speeding = false
speed = 25
script.Parent.Touched:Connect(function(hit)
if attached == false then
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
if plr then
if hit.Name == “RightFoot” or hit.Name == “LeftFoot” then
attached = true
ball.Parent = hit
for i, v in pairs(hit:GetChildren()) do
if v:IsA(“Motor6D”) then
local newV = v:Clone()
newV.Parent = ball
newV.Part0 = ball
newV.Part1 = ball.Parent
end
end
end
plr.PlayerGui:WaitForChild(“ScreenGui”) .Shoot.Visible = true
end
end
end)
game.ReplicatedStorage.ShootBall.OnServerEvent:Connect(function(plr)
if attached == true then
if ball.Parent.Name == “RightFoot” then
ball.RightAnkle:Destroy()
elseif ball.Parent.Name == “LeftFoot” then
ball.LeftAnkle:Destroy()
end
while wait(.1) do
if speeding == true then
ball.Velocity += Vector3.new(0.1,0,0.1)
end
if ball.Velocity.X > 0 or ball.Velocity.Z > 0 then
speeding = false
end
end
I know how to check if the player is touching a part(the ball) I just don’t know weather or not to fit that into
Script: Print when ball is touched
local part = workspace.Ball
part.Touched:Wait()
print(“part touched”)
function onPartTouched()
print(“part touched with Connect”)
end
local connection
connection = part.Touched:Connect(onPartTouched)
This is the script you need. Just chuck the stuff I gave you into the loop where attached is set to true. I’m a little busy right now, but if you need more help, I can certainly help you (later)!
I would use a function with a while loop that checks the player’s movement and plays/stops the animation when appropriate. You should have a model or something where both idle animations are placed, then you can use this code to make the animations work. animationModel.ballanim.Disabled = true
local function playerIdle()
local human = game.Players.LocalPlayer.Character.Humanoid
local animationModel = workspace.animationModel
local hasBall = game.Players.LocalPlayer.PlayerGui:FindFirstChild(“hasBall”).Value
local moveDirection = human.MoveDirection
while wait() do
if moveDirection == Vector3.new(0,0,0) then
if hasBall then
animationModel.ballanim.Disabled = false
animationModel.noballanim.Disabled = true
else
animationModel.ballanim.Disabled = true
animationModel.noballanim.Disabled = false
end
else
animationModel.ballanim.Disabled = true
animationModel.noballanim.Disabled = true
end
end
end