What would cause this script to only work for my self but no one else who was play testing it?

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want to learn why this script only works for me in my experience

  2. What is the issue? Include screenshots / videos if possible!
    I cant get a screen shot because the other person kind of left but basically the issue is that my script would work for me, but then when someone was play testing the script it didn’t work at all for them, they couldn’t move or animate or anything.

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    none because I’m no where close to understanding what’s causing this first time I encountered a bug like this before, I read through the code nothing looked like it could cause this so now I’m here to hopefully avoid something similar in the future

local player = game:GetService("Players").LocalPlayer
local playerScript = player:WaitForChild("PlayerScripts")
local playerModule = require(playerScript:WaitForChild("PlayerModule"))
local controls = playerModule:GetControls()
local UIS = game:GetService("UserInputService")
local RS = game:GetService("RunService")
local animateScript = script.Parent:WaitForChild("Animate")


-- animations
local Idle = script:WaitForChild("fighter1_Idle")
local duck = script:WaitForChild("fighter1_duck")
local falling = script:WaitForChild("fighter1_falling")
local jump = script:WaitForChild("fighter1_jump")
local hopeleft = script:WaitForChild("fighter_hopeLeft")
local hopeRight = script:WaitForChild("fighter_hopeRight")


wait(1)
animateScript:Destroy()
controls:Disable()

player.Character.Humanoid.JumpPower = 70

-- keyBools
local key_W_pressed = false
local key_A_pressed = false
local key_D_pressed = false
local key_S_pressed = false

local currentlyMoving = false
local idleInUse = true
local animationTrack  
local animationPlaying = false
local changeAnimation


local function animationHandler(movement)
	
	if idleInUse and animationPlaying == false then
		print(animationTrack)
		animationPlaying = true
		animationTrack = player.Character.Humanoid.Animator:LoadAnimation(Idle)
		animationTrack:Play()
		--animationTrack:AdjustSpeed(3)
	elseif idleInUse == false and animationPlaying == false then
		print(animationTrack)
		animationPlaying = true
		--animationTrack:Destroy()
		animationTrack:Stop()
		animationTrack = nil
		local animationTrack = player.Character.Humanoid.Animator:LoadAnimation(movement)
		animationTrack:AdjustSpeed(1.5)
		animationTrack:Play()
		animationTrack.Ended:Connect(function()
			idleInUse = true
			animationPlaying = false
			animationTrack:Destroy()
		end)
	end
end


local function movementHandler()
	print("w:",key_W_pressed,"a:",key_A_pressed,"d:",key_D_pressed,"s:",key_S_pressed)
	if key_W_pressed then
		if key_D_pressed then
			local movement = jump
			animationTrack:Stop()
			idleInUse = false
			animationPlaying = false
			animationHandler(movement)
			wait(0.2)
			local force = Instance.new("BodyVelocity")
			force.Parent = player.Character.HumanoidRootPart
			force.MaxForce = Vector3.new(10000000,10000000,10000000)
			force.Velocity = Vector3.new(-50,30,0)
			wait(0.1)
			force:Destroy()
			
		elseif key_A_pressed then
			local movement = jump
			animationTrack:Stop()
			idleInUse = false
			animationPlaying = false
			animationHandler(movement)
			wait(0.2)
			local force = Instance.new("BodyVelocity")
			force.Parent = player.Character.HumanoidRootPart
			force.MaxForce = Vector3.new(10000000,10000000,10000000)
			force.Velocity = Vector3.new(50,30,0)
			wait(0.1)
			force:Destroy()
			
		else
			local movement = jump
			animationTrack:Stop()
			idleInUse = false
			animationPlaying = false
			animationHandler(movement)
			wait(0.2)
			local force = Instance.new("BodyVelocity")
			force.Parent = player.Character.HumanoidRootPart
			force.MaxForce = Vector3.new(10000000,10000000,10000000)
			force.Velocity = Vector3.new(0,30,0)
			wait(0.1)
			force:Destroy()
			
		end
	end
	if key_D_pressed and not key_W_pressed then
		local movement = hopeRight
		animationTrack:Stop()
		idleInUse = false
		animationPlaying = false
		animationHandler(movement)
		wait(0.2)
		local force = Instance.new("BodyVelocity")
		force.Parent = player.Character.HumanoidRootPart
		force.MaxForce = Vector3.new(10000000,10000000,10000000)
		force.Velocity = Vector3.new(-50,0,0)
		wait(0.1)
		force:Destroy()
		
	end
	if key_A_pressed and not key_W_pressed then
		local movement = hopeleft
		animationTrack:Stop()
		idleInUse = false
		animationPlaying = false
		animationHandler(movement)
		wait(0.2)
		local force = Instance.new("BodyVelocity")
		force.Parent = player.Character.HumanoidRootPart
		force.MaxForce = Vector3.new(10000000,10000000,10000000)
		force.Velocity = Vector3.new(50,0,0)
		wait(0.1)
		force:Destroy()
		
	end
	if key_S_pressed then
		if player.Character.Humanoid:GetState() == Enum.HumanoidStateType.Freefall then
			local movement = duck
			animationTrack:Stop()
			idleInUse = false
			animationPlaying = false
			animationHandler(movement)
			wait(0.2)
			local force = Instance.new("BodyVelocity")
			force.Parent = player.Character.HumanoidRootPart
			force.MaxForce = Vector3.new(10000000,10000000,10000000)
			force.Velocity = Vector3.new(0,-50,0)
			wait(0.1)
			force:Destroy()
			
		else
			local movement = duck
			idleInUse = false
			animationPlaying = false
			animationHandler(movement)
		end
	
	end
	key_W_pressed = false
	key_A_pressed = false
	key_D_pressed = false
	key_S_pressed = false
end


UIS.InputBegan:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.Keyboard then
		if input.KeyCode == Enum.KeyCode.D then
			key_D_pressed = true
		end
	end
end)

UIS.InputBegan:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.Keyboard then
		if input.KeyCode == Enum.KeyCode.A then
			key_A_pressed = true
		end
	end
end)

UIS.InputBegan:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.Keyboard then
		if input.KeyCode == Enum.KeyCode.W then
			key_W_pressed = true
		end
	end
end)

UIS.InputBegan:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.Keyboard then
		if input.KeyCode == Enum.KeyCode.S then
			key_S_pressed = true
		end
	end
end)


local timer = 10
RS.Heartbeat:Connect(function()
	animationHandler()
	if timer == 0 then
		timer = 10
		movementHandler()
	else
		
		timer = timer - 1
	end
end)



So what does this script do?
btw it made some bug when I tested it

2 Likes

Yeah I’m aware of the animation bug, did it not work when you tested it because I mean it should have shown you what it does also you kind of need the animations other wise it might make break the script from working at all so you would have to comment out all the animation code before you test it actually. But the quick and simple is it was supposed to check for input combinations and create movement.

1 Like