Ball Kick Function doesn't working

Hey Everyone, my Ball Kick Function doesn’t work; how can I fix it?

  1. What do you want to achieve? I am making Ball Kick Function for my game, but it isn’t working.

  2. What is the issue? When the player uses the E Key on the keyboard, the Local Script must execute the function that comes with the Module Script. But when I test the game, nothing happens. I already tried to do anything; even the Remotes did not help.

At the bottom, there are scripts with which I did this function, Local Script - executes the process through the Module when the player presses the E key. Module Script - already runs the function itself.

Local Script:

local uis = game:GetService("UserInputService")
local rs = game:GetService("ReplicatedStorage")
local players = game:GetService("Players")

local modules = rs:FindFirstChild("Modules")
local module = require(modules.Functions)

local player = players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()

local ball = workspace.Ball
local keybind = Enum.KeyCode.E

local canKick = true

uis.InputBegan:Connect(function(input, gameProcessed)
	if gameProcessed then return end
	if input.KeyCode == keybind and canKick == true then
		if (character.HumanoidRootPart.Position - ball.Position).Magnitude < 4 then
			module.Kick(player)
		end
	end
end)

Module Script:

local module = {}

local velocity = 100
local canKick = false

local jumpVelocity = 5

local rs = game:GetService("ReplicatedStorage")
local events = rs:WaitForChild("Remotes").Events

local players = game:GetService("Players")

function module.Kick(player)
	local ball = workspace.Ball
	if not canKick then
		local character = player.Character or player.CharacterAdded:Wait()
		local humanoid = character:WaitForChild("Humanoid")

		local D = character.HumanoidRootPart.CFrame.LookVector
		local force = (-D + Vector3.new(0, workspace.Gravity / jumpVelocity, 0))

		ball:ApplyImpulse(force * ball.AssemblyMass)
		ball:ApplyImpulse(D * velocity * ball:GetMass())

		canKick = true
		task.wait(2.5)
		canKick = false
	end
end

return module

If someone helps, it would be appreciated! Thanks.

1 Like

Are you sure that the module.Kick() function is being executed? Also what do you mean by “even the Remotes did not help”

1 Like

Yeah, I used print() to sure that is working. And in Output, I can see that is working.

For like, I tried to use RemoteEvent.

1 Like

You have to make the local script fire a remote event and make a server script execute the module.Kick() function. Otherwise it wont work. You probably did something wrong while making it work with remotes

2 Likes

Hi! May can you try to put a print line after the Input.Keycode == keybind, because I’m not sure if the keybind will work as a local variable, because in some cases it doesn’t work. Also is the issue you have is with the module function or the localscript, because nothing happens.

1 Like

I would try to replace keybind to Enum.Keycode.E
Don’t say it can’t be an issue, just try it out, may it can help.

1 Like

Thanks! I fixed it. I just made everything you said, and it’s working now!

2 Likes

Wait. As you said, I think the UIS is working, but not the function?

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.