I’m having trouble with network ownership as you may have noticed, and its not consistent. I am working on an core ability I will be using in my game where when a player presses space bar they will make a super leap into the air and smash into the ground.
The problem is, yesterday I tried using AssemblyLinearVelocity and WalkSpeed on the server to work on this jumping mechanism, but I had to use remote events to fire these changes on the client. I’ve gone through this problem ago a while back but its been appearing up and down like a wave.
I want to confirm why this is happening. The last time I had this issue, its because another script in my game was stopping the code I had previously made a post on.
Here is my script now(It’s a little janky since I’ve been testing with it):
local ServerStorage = game:GetService("ServerStorage")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Impact = {}
Impact.__index = Impact
function Impact.new(player)
local self = setmetatable({},Impact)
self.Player = player
self.Character = self.Player.Character or self.Player.CharacterAdded:Wait()
self.Root = self.Character:WaitForChild("HumanoidRootPart")
self.Humanoid = self.Character.Humanoid
self.Params = RaycastParams.new()
self.Params.FilterDescendantsInstances = {self.Character,self.Impact}
self.Params.FilterType = Enum.RaycastFilterType.Exclude
self.Impact = script.GroundImpact:Clone()
self.Impact.Parent = ServerStorage -- Parent for now
return self
end
function Impact:Controls(signal)
if signal == "Disable" then
ReplicatedStorage.AdjustPlayerStats:FireClient(self.Player,"Controls",0,0,false)
elseif signal == "Enable" then
ReplicatedStorage.AdjustPlayerStats:FireClient(self.Player,"Controls",16,50,true)
end
end
function Impact:Init()
--self:Controls("Disable")
self.Humanoid.WalkSpeed = 250
ReplicatedStorage.AdjustPlayerStats:FireClient(self.Player,Vector3.new(0,250,0) + self.Root.CFrame.LookVector * 250,"Assembly")
task.wait(.5)
ReplicatedStorage.AdjustPlayerStats:FireClient(self.Player,Vector3.new(0,-250,0) + self.Root.CFrame.LookVector * 250,"Assembly")
--self:WaitForFloor()
end
function Impact:ColorizeParts()
for i,v in self.Impact:GetChildren() do
local origin = v.Position
local direction = v.CFrame.UpVector * -2
local result = workspace:Raycast(origin,direction,self.Params)
if result and result.Instance then
v.Color = result.Instance.Color
v.Material = result.Instance.Material
end
end
end
function Impact:JumpCast()
local origin = self.Root.Position
local direction = self.Root.CFrame.UpVector * -6
local result = workspace:Raycast(origin,direction,self.Params)
if result then
self.Impact.Parent = workspace
self.Impact:MoveTo(result.Position)
end
end
function Impact:Ground()
ReplicatedStorage.AdjustPlayerStats:FireClient(self.Player,Vector3.zero,"Assembly")
self:JumpCast()
self:ColorizeParts()
self:Controls("Enable")
end
function Impact:WaitForFloor()
local amplitude = (-self.Root.Size.Y/2 + -self.Character["Right Leg"].Size.Y)
repeat
print(amplitude)
local origin = self.Root.Position
local direction = self.Root.CFrame.UpVector * amplitude
local result = workspace:Raycast(origin,direction,self.Params)
if result then
print("TouchedGround")
self:Ground()
end
task.wait()
until result
end
return Impact