im really frustrated, i will provide the code if this isn’t just some dumb roblox bug. please help me.
You gotta show the code man.
Also, from the first error, it seems you have a Script
inside StarterCharacterScripts
with the RunContext
set to Client
.
nope. its not a script with a modified runcontext. it is a localscript.
here is the code, its messy but theres nothing in there that would cause this to happen
local plr = game.Players.LocalPlayer
local uis = game:GetService("UserInputService")
local emoting = false
local camera = workspace.Camera
local cas = game:GetService("ContextActionService")
--Movement related hotkeys
local UserInputService = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local DashAnimation = script:WaitForChild('DashAnim')
local SprintAnimation = script:WaitForChild('SprintAnim')
-- Settings
local key = Enum.KeyCode.LeftShift -- key to trigger dash
local velocity = 7500 -- dash speed
local debounce = false -- debounce, do not set to true
local cooldown = 2.5 -- cooldown after dash
local duration = 0.7 -- dash duration
--Local script in StarterPlayerCharacter
--Services:
local UserInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
--Variables:
local char = player.Character or player.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")
local root = char:WaitForChild("HumanoidRootPart") -- The HumanoidRootPart
print("Character Name:", char.Name)
--Toggle Function:
function shiftLock(active) --Toggle shift.lock function
if active then
hum.CameraOffset = Vector3.new(1.75,0,0) -- I assume this is about the right camera offset.
hum.AutoRotate = false --Disable the automatic rotation since we are the ones setting it.
RunService:BindToRenderStep("ShiftLock", Enum.RenderPriority.Character.Value, function()
UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter --Set the mouse to center every frame.
local _, y = workspace.CurrentCamera.CFrame.Rotation:ToEulerAnglesYXZ() --Get the angles of the camera
root.CFrame = CFrame.new(root.Position) * CFrame.Angles(0,y,0) --Set the root part to the camera's rotation
end)
else
hum.CameraOffset = Vector3.new(0,0,0) --Move the camera back to normal.
RunService:UnbindFromRenderStep("ShiftLock") -- Allow mouse to move freely.
UserInputService.MouseBehavior = Enum.MouseBehavior.Default -- Let the mouse move freely
hum.AutoRotate = true --Let the humanoid handle the camera rotations again.
end
end
--Disable and Enable:
shiftLock(true) -- Toggle shift lock
local function Slide()
local character = player.Character or player.CharacterAdded:Wait()
if character and not debounce then
debounce = true
-- now we begin the dash script here
local humanoid = character.Humanoid
local HRP = character.HumanoidRootPart -- HRP stands for HumanoidRootPart
local loadedAnimation = humanoid:LoadAnimation(DashAnimation)
local dashDirection = nil
local moveDirection = humanoid.MoveDirection
local lookVector = HRP.CFrame.LookVector
local minusVelocity = -velocity -- in CFrame, if we set Z to positive, player will go move backward
-- instead of forward
-- checking if player is on ground, not floating
local isOnGround = humanoid.FloorMaterial ~= Enum.Material.Air and humanoid.FloorMaterial ~= Enum.Material.Water
if isOnGround and humanoid.WalkSpeed > 20 then
if moveDirection == Vector3.new(0,0,0) then -- if player is not currently moving/walking
dashDirection = HRP.Position + Vector3.new(lookVector.X, 0, lookVector.Z)
else -- if player are currently moving/walking
dashDirection = HRP.Position + Vector3.new(moveDirection.X, 0, moveDirection.Z)
end
-- using bodygyro to rotate player to the dash direction smoothly
local bodyGyro = Instance.new("BodyGyro")
bodyGyro.Parent = HRP
bodyGyro.MaxTorque = Vector3.new(math.huge, math.huge, math.huge)
bodyGyro.D = 0 -- D is the dampening
bodyGyro.P = 10000000 -- P is aggressiveness
bodyGyro.CFrame = CFrame.lookAt(HRP.Position, dashDirection) -- Making player look at the dash direction
local attachment = Instance.new("Attachment")
attachment.Parent = HRP
-- now using VectorForce to move player forward
local vectorForce = Instance.new("VectorForce")
vectorForce.Parent = HRP
-- VectorForce need attachment to tell where is player looking at
vectorForce.Attachment0 = attachment
vectorForce.Force = Vector3.new(0,0,minusVelocity) -- now it will move player forward as the settings
shiftLock(false)
char.Sliding.Value = true
loadedAnimation:Play() -- play the dash animation
local ws = tonumber(humanoid.WalkSpeed)
humanoid.WalkSpeed = 0
humanoid.AutoRotate = false -- prevent player to rotate by themselves
local Properties = {FieldOfView = 100} -- change the number as you wish
local Info = TweenInfo.new(0.5, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut) -- edit as you want
local T = game:GetService("TweenService"):Create(game.Workspace.CurrentCamera, Info, Properties)
T:Play()
game.Players.LocalPlayer.PlayerGui.DashEffect.Enabled = true
script.Smoke:Clone().Parent = character["Left Leg"]
script.Smoke:Clone().Parent = character["Right Leg"]
wait(duration)
humanoid.AutoRotate = true
humanoid.Parent.PrimaryPart.Anchored = true
vectorForce:Destroy()
bodyGyro:Destroy()
attachment:Destroy()
--wait(duration) -- give some time before stopping the dash animation
shiftLock(true)
char.Sliding.Value = false
loadedAnimation:Stop()
humanoid.WalkSpeed = ws
local Properties = {FieldOfView = 70} -- change the number as you wish
local Info = TweenInfo.new(0.5, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut) -- edit as you want
local T = game:GetService("TweenService"):Create(game.Workspace.CurrentCamera, Info, Properties)
T:Play()
game.Players.LocalPlayer.PlayerGui.DashEffect.Enabled = false
character["Left Leg"].Smoke:Destroy()
character["Right Leg"].Smoke:Destroy()
wait(0.01)
humanoid.Parent.PrimaryPart.Anchored = false
end
wait(cooldown)
debounce = false
end
end
local char = player.Character or player.CharacterAdded:Wait()
local key2 = Enum.KeyCode.LeftControl -- key to trigger dash
local humanoid = char:WaitForChild("Humanoid")
local HRP = char:WaitForChild("HumanoidRootPart") -- HRP stands for HumanoidRootPart
local loadedAnimation = humanoid:LoadAnimation(SprintAnimation)
local UIS = game:GetService("UserInputService")
local DefaultFOV = 70
local lastTime = tick()
local player = game.Players.LocalPlayer
local hum = char:WaitForChild("Humanoid")
local run = false
local Track1
UIS.InputBegan:Connect(function(input,gameprocessed)
if input.KeyCode == Enum.KeyCode.W then
local now = tick()
local difference = (now - lastTime)
if difference <= 0.5 then
run = true
loadedAnimation:Play()
print("running")
hum.WalkSpeed = 30
local properties = {FieldOfView = DefaultFOV + 15}
local Info = TweenInfo.new(0.5,Enum.EasingStyle.Sine,Enum.EasingDirection.InOut,0.1)
local T = game:GetService("TweenService"):Create(game.Workspace.CurrentCamera,Info,properties)
T:Play()
spawn(function()
while run == true do
wait(1)
player.Data.Stamina.Value = player.Data.Stamina.Value - 1
hum.WalkSpeed -= 1
loadedAnimation:AdjustSpeed(loadedAnimation.Speed - 1/20)
end
end)
spawn(function()
while true do
wait(1)
if hum.WalkSpeed == 16 then
run = false
if loadedAnimation then
loadedAnimation:Stop()
loadedAnimation:AdjustSpeed(1)
end
hum.WalkSpeed = 16
local properties = {FieldOfView = DefaultFOV}
local Info = TweenInfo.new(0.5,Enum.EasingStyle.Sine,Enum.EasingDirection.InOut,0.1)
local T = game:GetService("TweenService"):Create(game.Workspace.CurrentCamera,Info,properties)
T:Play()
wait(10)
player.Data.Stamina.Value = 7
end
end
end)
end
lastTime = tick()
end
end)
UIS.InputEnded:Connect(function(input,gameprocessed)
if input.KeyCode == Enum.KeyCode.W then
run = false
if loadedAnimation then
loadedAnimation:Stop()
loadedAnimation:AdjustSpeed(1)
end
print("running")
hum.WalkSpeed = 16
local properties = {FieldOfView = DefaultFOV}
local Info = TweenInfo.new(0.5,Enum.EasingStyle.Sine,Enum.EasingDirection.InOut,0.1)
local T = game:GetService("TweenService"):Create(game.Workspace.CurrentCamera,Info,properties)
T:Play()
end
end)
UserInputService.InputBegan:Connect(function(input)
if input.KeyCode == key then
Slide()
end
end)
its messy because its an amalgamation of movement mechanics ive made throughout years, so i was too lazy to remove all the duplicate variables, however that literally CANNOT cause my issue. ALSO it works just fine in studio. i have been dealing with so many strange errors when it comes to local scripts in the character that ive never experienced before while working on this game for the past 3 days, so im suspecting that something is just messed up with roblox’s api
Yeah, it is extremely messy and extremely prone to bugs from a glance. You should take the time to rework it. If your code works in studio, it is likely due to the fact that loading behavior varies in studio vs in a live game, and it is very hard to pinpoint where it exactly goes wrong. Try adding prints outside of your functions to see where it ends.
Regarding your console, can you take a screenshot of the entire output and not just these lines? It’s very hard to tell, but the console might be bugging out from possible long stack traces, but I cannot say for sure.
I think I’m lost, but why put this script in StarterCharacterScripts? Doesn’t this parent it to the Character in workspace? I must be wrong but wouldn’t this not work anyways?
it was working just fine, localscripts run as long as they are in a client owned object, so yes they do run inside the character in the workspace
Oh okay, I forgot. I never use it is why, but also in your code I see you put “UserInputService.InputBegan” and “UIS.InputBegan” in the same script? This also could cause problems, but not relating to whatever random bug the output is showing.
its a repeated variable yes, but it hasn’t caused me to run into any issues. ive been bug fixing this script for like 2 days now and whenever i fix a bug, a new one seems to appear, and it always has to do with character loading, character replication, etc. which is why i suspect this is a roblox bug
Looks like a old script and model were used and you don’t have total permission for a few sounds in it and didn’t sanitize the animations for you to use. Possibly now messing with a default script.
i dont care about the sounds and asset warnings they are totally irrelevant to my issue. also i just fixed it. i dont know how or why but just putting it into a new local script with literally the same exact code, it runs just fine
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.