You can write your topic however you want, but you need to answer these questions:
- What do you want to achieve? Keep it simple and clear!
A sprint script that checks the class’ maxSpeed attribute value and ensures that the character’s speed does not exceed that value.
- What is the issue? Include screenshots / videos if possible!
It does not run after a new character is loaded in. It prints the maxSpeed value on the client twice after their character is switched, but the sprinting itself only works on the default character that you spawn in as.
- What solutions have you tried so far? Did you look for solutions on the Creator Hub?
I have tried a ton of messing around with player.CharacterAdded, which often fixed one problem and created another, or just didn’t work altogether. I checked and asked for solutions on multiple roblox scripting servers and looked for similar issues here, also to no benefit.
Sprint (local script in StarterCharacterScripts)
local Player = game:GetService("Players").LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local UIS = game:GetService("UserInputService")
--local clientHandler = require(game:GetService("StarterPlayer").ClientHandler)
local isRunning = false
local SPD = Character:GetAttribute("maxSpeed")
Player.CharacterAdded:Connect(function(char)
SPD = char:GetAttribute("maxSpeed")
print("maxSpeed: " ..SPD)
end)
UIS.InputBegan:Connect(function(input, gp)
if gp then return end
if input.KeyCode == Enum.KeyCode.LeftControl and Humanoid.MoveDirection.Magnitude > 0 then
if isRunning == false then
Humanoid.WalkSpeed = SPD
elseif isRunning then
Humanoid.WalkSpeed = 16
end
end
end)
ClassLoader In ServerScriptService:
SwitchEvent.OnServerEvent:Connect(function(player, camPos)
print("Server")
local pos = player.Character.PrimaryPart.CFrame
ClassMod:random(player) --Randomizes class selection
player:LoadCharacter() -Reloads the character
ClassMod:Replace(player) -Replaces them with the character of the selected class
player.Character.PrimaryPart.CFrame = pos
--print(camPos)
camPos = camPos
end)
I am also worried about the security of storing a character’s max speed in an attribute. Wouldn’t an exploiter be able to just change it via :setAttribute and run as fast as they want? I do plan to rescript sprint but I need to make sure this rough draft will work first.