Hey fellow devs! I ran into an issue while scripting.
Either the math.random or the boolean value event is not being called when the touch event occurs. I need help to try to fix this script please.
Here is the portion of it that I need help with:
elseif workspace.truck.Value == true then
if OtherPlayerChar:FindFirstChild("Football") then return end
local randomnumber = math.random(1,3)
print(randomnumber)
local debounce3 = false
if not debounce3 then
debounce3 = true
print("Trucked")
workspace.HBPH:Play()
workspace.HPH:Play()
-- Dummy Movement
if workspace.hitstick.Value == true then
if randomnumber == 1 then
print("Random = 1!")
OtherPlayerChar.Humanoid.PlatformStand = true
if (not Player.Character:FindFirstChild("PushForce")) and (not OtherPlayerChar:FindFirstChild("PushForce")) then
local PushForce = Instance.new("BodyVelocity")
PushForce.Name = "PushForce"
PushForce.MaxForce = Vector3.new(100000000, 100000000, 100000000)
PushForce.Velocity = (-OtherPlayerChar.HumanoidRootPart.CFrame.LookVector) * 20
PushForce.Parent = OtherPlayerChar.HumanoidRootPart
wait(0.25)
PushForce:Destroy()
end
wait(1)
OtherPlayerChar.Humanoid.PlatformStand = false
elseif randomnumber == 2 then
print("Random = 2!")
Player.Character.Humanoid.PlatformStand = true
if (not Player.Character:FindFirstChild("PushForce")) and (not OtherPlayerChar:FindFirstChild("PushForce")) then
local PushForce = Instance.new("BodyVelocity")
PushForce.Name = "PushForce"
PushForce.MaxForce = Vector3.new(100000000, 100000000, 100000000)
PushForce.Velocity = (-Player.Character.HumanoidRootPart.CFrame.LookVector) * 20
PushForce.Parent = Player.Character.HumanoidRootPart
wait(0.25)
PushForce:Destroy()
end
wait(1)
Player.Character.Humanoid.PlatformStand = false
elseif randomnumber == 3 then
print("Random = 2!")
Player.Character.Humanoid.PlatformStand = true
OtherPlayerChar.Humanoid.PlatformStand = true
if (not Player.Character:FindFirstChild("PushForce")) and (not OtherPlayerChar:FindFirstChild("PushForce")) then
local PushForce = Instance.new("BodyVelocity")
PushForce.Name = "PushForce"
PushForce.MaxForce = Vector3.new(100000000, 100000000, 100000000)
PushForce.Velocity = (-Player.Character.HumanoidRootPart.CFrame.LookVector) * 20
PushForce.Parent = Player.Character.HumanoidRootPart
local PushForce2 = Instance.new("BodyVelocity")
PushForce.Name = "PushForce"
PushForce.MaxForce = Vector3.new(100000000, 100000000, 100000000)
PushForce.Velocity = (-OtherPlayerChar.HumanoidRootPart.CFrame.LookVector) * 20
PushForce.Parent = OtherPlayerChar.HumanoidRootPart
wait(0.25)
PushForce:Destroy()
end
wait(1)
Player.Character.Humanoid.PlatformStand = false
end
end
OtherPlayerChar.Humanoid.PlatformStand = true
wait(1)
OtherPlayerChar.Humanoid.PlatformStand = false
wait(1)
debounce3 = false
end
end
end
end)
The full script:
local Player = game.Players:GetPlayerFromCharacter(script.Parent.Parent)
script.Parent.Touched:Connect(function(Part)
local OtherPlayer = game.Players:GetPlayerFromCharacter(Part.Parent)
local OtherPlayerChar = Part.Parent
local Jersey = Part
if Jersey.Name == "Jersey2" then
if workspace.hitstick.Value == true then
local debounce = false
if not debounce then
debounce = true
print("Hit")
workspace.HBPH:Play()
workspace.HPH:Play()
-- Dummy Movement
Jersey.Position = Jersey.Position - Vector3.new(0,0,1)
Jersey.Orientation = Vector3.new(-30, 0, 0)
if math.random(1,5) == 3 then
Jersey.Anchored = false
print("Broke Off!")
end
wait(0.75)
if Jersey.Anchored == false then return end
Jersey.Position = Jersey.Position + Vector3.new(0,0,1)
Jersey.Orientation = Vector3.new(0, 0, 0)
wait(5)
debounce = false
end
elseif workspace.block.Value == true then
local debounce2 = false
if not debounce2 then
debounce2 = true
print("Blocked")
workspace.HBPH:Play()
-- Dummy Movement
Jersey.Position = Jersey.Position - Vector3.new(0,0,1)
Jersey.Orientation = Vector3.new(-30, 0, 0)
wait(0.75)
Jersey.Position = Jersey.Position + Vector3.new(0,0,1)
Jersey.Orientation = Vector3.new(0, 0, 0)
wait(1)
debounce2 = false
end
end
-- REAL PLAYERS
elseif Jersey.Name == "Jersey" then
if workspace.hitstick.Value == true then
if workspace.truck.Value == true then return end
if not OtherPlayerChar:FindFirstChild("Football") then return end
local debounce = false
if not debounce then
debounce = true
print("Hit")
workspace.HBPH:Play()
workspace.HPH:Play()
-- Player Movement
OtherPlayerChar.Humanoid.PlatformStand = true
if (not Player.Character:FindFirstChild("PushForce")) and (not OtherPlayerChar:FindFirstChild("PushForce")) then
local PushForce = Instance.new("BodyVelocity")
PushForce.Name = "PushForce"
PushForce.MaxForce = Vector3.new(100000000, 100000000, 100000000)
PushForce.Velocity = (-OtherPlayerChar.HumanoidRootPart.CFrame.LookVector) * 20
PushForce.Parent = OtherPlayerChar.HumanoidRootPart
wait(0.25)
PushForce:Destroy()
end
wait(1)
OtherPlayerChar.Humanoid.PlatformStand = false
wait(5)
debounce = false
end
elseif workspace.block.Value == true then
local debounce2 = false
if not debounce2 then
debounce2 = true
print("Blocked")
-- Dummy Movement
if (not Player.Character:FindFirstChild("PushForce")) and (not OtherPlayerChar:FindFirstChild("PushForce")) then
local PushForce = Instance.new("BodyVelocity")
PushForce.Name = "PushForce"
PushForce.MaxForce = Vector3.new(100000000, 100000000, 100000000)
PushForce.Velocity = (-OtherPlayerChar.HumanoidRootPart.CFrame.LookVector) * 9.5
PushForce.Parent = OtherPlayerChar.HumanoidRootPart
wait(0.25)
PushForce:Destroy()
end
wait(1)
debounce2 = false
end
elseif workspace.truck.Value == true then
if OtherPlayerChar:FindFirstChild("Football") then return end
local randomnumber = math.random(1,3)
print(randomnumber)
local debounce3 = false
if not debounce3 then
debounce3 = true
print("Trucked")
workspace.HBPH:Play()
workspace.HPH:Play()
-- Dummy Movement
if workspace.hitstick.Value == true then
if randomnumber == 1 then
print("Random = 1!")
OtherPlayerChar.Humanoid.PlatformStand = true
if (not Player.Character:FindFirstChild("PushForce")) and (not OtherPlayerChar:FindFirstChild("PushForce")) then
local PushForce = Instance.new("BodyVelocity")
PushForce.Name = "PushForce"
PushForce.MaxForce = Vector3.new(100000000, 100000000, 100000000)
PushForce.Velocity = (-OtherPlayerChar.HumanoidRootPart.CFrame.LookVector) * 20
PushForce.Parent = OtherPlayerChar.HumanoidRootPart
wait(0.25)
PushForce:Destroy()
end
wait(1)
OtherPlayerChar.Humanoid.PlatformStand = false
elseif randomnumber == 2 then
print("Random = 2!")
Player.Character.Humanoid.PlatformStand = true
if (not Player.Character:FindFirstChild("PushForce")) and (not OtherPlayerChar:FindFirstChild("PushForce")) then
local PushForce = Instance.new("BodyVelocity")
PushForce.Name = "PushForce"
PushForce.MaxForce = Vector3.new(100000000, 100000000, 100000000)
PushForce.Velocity = (-Player.Character.HumanoidRootPart.CFrame.LookVector) * 20
PushForce.Parent = Player.Character.HumanoidRootPart
wait(0.25)
PushForce:Destroy()
end
wait(1)
Player.Character.Humanoid.PlatformStand = false
elseif randomnumber == 3 then
print("Random = 2!")
Player.Character.Humanoid.PlatformStand = true
OtherPlayerChar.Humanoid.PlatformStand = true
if (not Player.Character:FindFirstChild("PushForce")) and (not OtherPlayerChar:FindFirstChild("PushForce")) then
local PushForce = Instance.new("BodyVelocity")
PushForce.Name = "PushForce"
PushForce.MaxForce = Vector3.new(100000000, 100000000, 100000000)
PushForce.Velocity = (-Player.Character.HumanoidRootPart.CFrame.LookVector) * 20
PushForce.Parent = Player.Character.HumanoidRootPart
local PushForce2 = Instance.new("BodyVelocity")
PushForce.Name = "PushForce"
PushForce.MaxForce = Vector3.new(100000000, 100000000, 100000000)
PushForce.Velocity = (-OtherPlayerChar.HumanoidRootPart.CFrame.LookVector) * 20
PushForce.Parent = OtherPlayerChar.HumanoidRootPart
wait(0.25)
PushForce:Destroy()
end
wait(1)
Player.Character.Humanoid.PlatformStand = false
end
end
OtherPlayerChar.Humanoid.PlatformStand = true
wait(1)
OtherPlayerChar.Humanoid.PlatformStand = false
wait(1)
debounce3 = false
end
end
end
end)