I am making a soccer/football-based game and I have got to the point where I am trying to work on the passes, starting with a low one. But I have come to a problem whilst doing so.
Here’s the scenario: there’s a tool in StarterPack with a script inside it, an event in ReplicatedStorage, and a script within the ball that is placed in Workspace. The script within the tool is told to run a Loop to determine the amount of power. After running this loop, it creates a new NumberValue within the RemoteEvent in ReplicatedStorage containing the value. And then it fires the event which triggers the ball to react if it was touched during the event. The number value of which, destroys in 1 second using Debris.
Heres the problem: the Power loop works perfectly as well as the event and NumberValue, what isnt working is the ball script. When touched by the players foot after all this occurs, it doesnt pick up the NumberValue’s value, leading to the output saying infinite yeild.
Solutions I’ve Tried: I’ve tried just putting a set NumberValue object in the event and just changing its value each time a new power was made. Sadly, the ball script ends up taking the original value set before anything is actually changed. I am starting to think this is just a Client to Server communication issue, which I commonly mess up at times. I’m also trying many different printing techniques to try and pinpoint the exact problem and it all lies down to them just not connecting correctly.
Note: I think can be fixed quite easily and end up with me feeling bad for not noticing but if you do find a solution it’ll be greatly appreciated.
Tool Script:
local Services = {
Players = game:GetService("Players"),
ReplicatedStorage = game:GetService("ReplicatedStorage"),
Workspace = game:GetService("Workspace"),
UserInputService = game:GetService("UserInputService"),
Debris = game:GetService("Debris")
}
local reFolder = Services.ReplicatedStorage:WaitForChild("RemoteEvents")
local Events = {
lpassEvent = reFolder:FindFirstChild("LPassRE")
}
local tool = script.Parent
local toolOn = false
local pwrdebounce = false
local player = Services.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
local Animations = {
lpass = Instance.new("Animation")
}
Animations.lpass.AnimationId = "rbxassetid://17644737293"
Animations.lpass.Parent = script.Parent.Anims
local lpassTrack = animator:LoadAnimation(Animations.lpass)
local function onAction(track, event)
track:Play()
event:FireServer()
end
local function onPowerScroll(button, track, event)
if button and pwrdebounce == false then
pwrdebounce = true
for power = 0, 100, 1 do
print(power .. "%")
task.wait(0.0005)
if Services.UserInputService:IsKeyDown(Enum.KeyCode.E) == false then
print("stop! " .. power .. "% power used!")
local PowerVal = Instance.new("NumberValue")
PowerVal.Parent = event
PowerVal.Name = "Power"
PowerVal.Value = power
pwrdebounce = false
onAction(track, event)
Services.Debris:AddItem(PowerVal, 1)
break
elseif power == 100 then
wait(5)
local PowerVal = Instance.new("NumberValue")
PowerVal.Parent = event
PowerVal.Name = "Power"
PowerVal.Value = power
pwrdebounce = false
onAction(track, event)
Services.Debris:AddItem(PowerVal, 1)
else
print("keep goin")
end
end
end
end
tool.Equipped:Connect(function()
toolOn = true
end)
tool.Unequipped:Connect(function()
toolOn = false
end)
Services.UserInputService.InputBegan:Connect(function(input, gameProcessedEvent)
local eHeld = Services.UserInputService:IsKeyDown(Enum.KeyCode.E)
if toolOn == true then
onPowerScroll(eHeld, lpassTrack, Events.lpassEvent)
end
end)
-- Tons of script has been removed for your convenience.
-- Ignore some prints, they're just to check the functionality.
Ball Script:
ocal Services = {
Players = game:GetService("Players"),
Debris = game:GetService("Debris"),
ReplicatedStorage = game:GetService("ReplicatedStorage"),
Workspace = game:GetService("Workspace"),
RunService = game:GetService("RunService")
}
local reFolder = Services.ReplicatedStorage:WaitForChild("RemoteEvents")
local Events = {
drib = reFolder:FindFirstChild("DribbleRE"),
Fdrib = reFolder.FDribbleRE,
flick = reFolder.FlickUpRE,
lpass = reFolder.LPassRE -- Main Focus
}
local Activates = {
drib = false,
Fdrib = false,
flick = false,
lpass = false -- Main Focus
}
local ball = script.Parent
local Table = {}
Events.lpass.OnServerEvent:Connect(function()
Activates.lpass = true
wait(0.3)
Activates.lpass = false
end)
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(Table, Player) then
return
end
if Activates.lpass == true then
local Power = Events.lpass:WaitForChild("Power")
local Pwrval = Power.Value
onBallActive(Root, 20, Pwrval)
print("lpass")
Activates.lpass = false
end
end)
-- Tons of script has been removed for your convenience.
-- Ignore some prints, they're just to check the functionality.
Thank you in advance I will now head to school.