I dont know how to use onTouched events, im a little stuck on how to make a keybind for this ball script
Here’s the code:
> --Coded by thespecialnone (for my fighterz easter egg)
> local Services = {
> Players = game:GetService("Players"),
> Debris = game:GetService("Debris")
>
> }
> local Settings = {
> Kick_Cooldown = 1,
> Kick_Force = 20
> }
> local Ball = script.Parent
> local KickSound = Ball:WaitForChild("Kick")
> local IgnoreTable = {}
>
> Ball.Touched:Connect(function(Part)
> local Character = Part.Parent
> if not Character then
> return
> end
> local Player = Services.Players:GetPlayerFromCharacter(Character)
> local Humanoid = Character:FindFirstChildOfClass("Humanoid")
> local Root = Character:FindFirstChild("HumanoidRootPart")
> if not Player or not Humanoid or Humanoid.Health <= 0 or not Root or table.find(IgnoreTable, Player) then
> return
> end
> table.insert(IgnoreTable, Player)
> delay(Settings.Kick_Cooldown, function()
> if not Player then
> return
> end
> local Position = table.find(IgnoreTable, Player)
> if not Position then
> return
> end
> table.remove(IgnoreTable, Position)
> end)
> local Direction = CFrame.lookAt(Root.Position, Ball.Position).LookVector
> if Direction.Magnitude < 0.001 then
> return
> end
> local Velocity = Instance.new("BodyVelocity")
> Velocity.Parent = Ball
> Velocity.MaxForce = Vector3.new(1, 1, 1) * math.huge
> Velocity.Velocity = (Direction.Unit * Settings.Kick_Force) + Vector3.new(0, Settings.Kick_Force /1.05, 0)
> Services.Debris:AddItem(Velocity, 0.2)
> KickSound:Play()
> end)
Use a RemoteEvent to send information from the client, and handle visuals on the server.
-- LocalScript
local RS = game:GetService("ReplicatedStorage")
local UIS = game:GetService("UserInputService")
UIS.InputBegan:Connect(function(input, processed)
if processed then return end
if input.KeyCode == Enum.KeyCode.F then
RS.RemoteEvent:FireServer()
end
end)
-- ServerScript
local Services = {
Players = game:GetService("Players");
Debris = game:GetService("Debris");
RS = game:GetService("ReplicatedStorage")
}
local Settings = {
Kick_Cooldown = 1,
Kick_Force = 20
}
local Ball = script.Parent
local KickSound = Ball:WaitForChild("Kick")
local IgnoreTable = {}
Services.RS.RemoteEvent.OnServerEvent:Connect(function(client)
local Character = client.Character
if not Character then return end
local Humanoid = Character:FindFirstChildOfClass("Humanoid")
local Root = Character:FindFirstChild("HumanoidRootPart")
if not client or not Humanoid or Humanoid.Health <= 0 or not Root or table.find(IgnoreTable, client) then
return
end
table.insert(IgnoreTable, client)
delay(Settings.Kick_Cooldown, function()
if not client then
return
end
local Position = table.find(IgnoreTable, client)
if not Position then
return
end
table.remove(IgnoreTable, Position)
end)
local Direction = CFrame.lookAt(Root.Position, Ball.Position).LookVector
if Direction.Magnitude < 0.001 then
return
end
local Velocity = Instance.new("BodyVelocity")
Velocity.Parent = Ball
Velocity.MaxForce = Vector3.new(1, 1, 1) * math.huge
Velocity.Velocity = (Direction.Unit * Settings.Kick_Force) + Vector3.new(0, Settings.Kick_Force /1.05, 0)
Services.Debris:AddItem(Velocity, 0.2)
KickSound:Play()
end)
local UserInputService = game:GetService("UserInputService")
local function onInputEnded(inputObject, gameProcessedEvent)
if gameProcessedEvent then return end
if inputObject.UserInputType == Enum.UserInputType.Keyboard then
if inputObject.KeyCode == Enum.KeyCode.E then -- change this to whatever key you want
print("E")
end
end
end
UserInputService.InputEnded:Connect(onInputEnded)
oh no, i don’t have a problem with that, my problem was in the first place that i have a touch football script that activates every time you touch the ball, my friend who owns the game wants a keybind script and completly rip out the touch football bit
you got it in this post