So I am making a rage game, and I have the system ready. What do you think of it?
Although it has some bugs, I think I can make it better.
Server Script:
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local throwEvent = ReplicatedStorage:WaitForChild("Events"):WaitForChild("Throw")
local DiscTemplate = ReplicatedStorage:WaitForChild("Models"):WaitForChild("PlayerDisc")
local playerDiscs = {}
Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
if playerDiscs[player] then
playerDiscs[player]:Destroy()
playerDiscs[player] = nil
end
local humanoid = character:WaitForChild("Humanoid") :: Humanoid
local hrp = character:WaitForChild("HumanoidRootPart")
local Disc = DiscTemplate:Clone()
Disc.Name = player.Name .. "_Disc"
Disc.Parent = workspace.Discs
Disc.Anchored = false
Disc.Color = BrickColor.random().Color
Disc.CFrame = hrp.CFrame * CFrame.Angles(0, math.rad(90), math.rad(90))
local rotation = CFrame.Angles(0, -math.rad(90), 0)
character:PivotTo(Disc.CFrame * rotation)
local scale = 0.7
character:ScaleTo(scale)
humanoid.WalkSpeed = 0
humanoid.JumpPower = 0
humanoid.PlatformStand = true
local weld = Instance.new("WeldConstraint")
weld.Part0 = hrp
weld.Part1 = Disc
weld.Parent = Disc
playerDiscs[player] = Disc
end)
end)
throwEvent.OnServerEvent:Connect(function(player, direction, power)
local Disc = playerDiscs[player]
if not Disc then return end
direction = Vector3.new(direction.X, 0, direction.Z).Unit
local bodyVelocity = Instance.new("BodyVelocity")
bodyVelocity.Velocity = direction * power
bodyVelocity.MaxForce = Vector3.new(1e6, 0, 1e6)
bodyVelocity.P = 5000
bodyVelocity.Parent = Disc
game.Debris:AddItem(bodyVelocity, 0.2)
end)
Local script
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local replicatedStorage = game:GetService("ReplicatedStorage")
local throwEvent = replicatedStorage:WaitForChild("Events"):WaitForChild("Throw")
local debounce = false
mouse.Button1Up:Connect(function()
if debounce then return end
debounce = true
local character = player.Character
if not character then return end
local head = character:FindFirstChild("Head")
if not head then return end
local mousePos = mouse.Hit.Position
local direction = (head.Position - mousePos).Unit
local power = (mousePos - character.PrimaryPart.Position).Magnitude * 3
local maxPower = 50
if power > maxPower then
power = maxPower
end
throwEvent:FireServer(direction, power)
task.wait(0.2)
debounce = false
end)