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

Can somebody tell me how to fix this? Nothing in the output.

This script's supposed to push the player back, someone fixed it for me, and when you press "f", if your mouse is on the player then it'll push the player backwards, and it'll play an animation looking like you pushed them, but it didn't work?? It didn't even play the animation, he told me to make it local and put into workspace did that didn't work.

wait()

 

local User = game.Players.LocalPlayer

local UserMouse = User:GetMouse()

Animation = Instance.new("Animation")

Animation.AnimationId = "http://www.roblox.com/Asset?ID=165757504"

Animation.Name = "Force push."

local animTrack = User.Character.Humanoid:LoadAnimation(Animation)

 

 

while wait() do

    if UserMouse .Target then

        if UserMouse .Target.Parent:FindFirstChild("Humanoid") or   UserMouse.Target.Parent.Parent:FindFirstChild("Humanoid") then

            UserMouse.KeyDown:connect(function(key) -- keydown function

                   if key == "f" then

                        animTrack:Play()

                  end

            end)

        else

            animTrack:Stop()

        end
    end

end


2 answers

wait(5) -- Wait for the Character to load



local User = game.Players.LocalPlayer

local mouse = User:GetMouse()

Animation = Instance.new("Animation")

Animation.AnimationId = "http://www.roblox.com/Asset?ID=165757504"

Animation.Name = "Force push."

local animTrack = User.Character.Humanoid:LoadAnimation(Animation)

forceValue = 100 -- The ammount of force to use, for easy changeing



function ForcePush(key) --This function is run every time that a person presses a button on the Keyboard
	if key == "f" then -- Checks if the button is F
		if mouse.Target ~= nil and mouse.Target:IsA("BasePart") then -- Checks if the mouse is over a part
			if mouse.Target.Parent:IsA("Hat") then -- If its over a hat
				animTrack:Play() --Plays Anim
				mouse.Target.Parent.Parent.Torso.Velocity = (workspace.CurrentCamera.CoordinateFrame.lookVector*forceValue) + Vector3.new(0,70,0) -- Forces
			elseif mouse.Target.Parent:FindFirstChild("Humanoid") then -- If its over a body part
				animTrack:Play() --Plays Anim
				mouse.Target.Parent.Torso.Velocity = (workspace.CurrentCamera.CoordinateFrame.lookVector*forceValue) + Vector3.new(0,70,0) -- Forces
			end
		end
	end
end


mouse.KeyDown:connect(ForcePush) -- This runs that function when the player presses a button

That while loop is doing nothing, and is the reason it is also not working, all you need to do is define the function, then give it a connector

I also did the force part for you, all it is is looking at the direction the camera is facing, and pushing the humanoid that way, plus a small amount of upward thrust

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