Hey Everyone, my Ball Kick Function doesn’t work; how can I fix it?
-
What do you want to achieve? I am making Ball Kick Function for my game, but it isn’t working.
-
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.