#help relating to data storage

1 messages · Page 1 of 1 (latest)

drowsy flume
#

i am quite new to scripting and have been experimenting with the tween service as well as user input service. i threw together a shift to sprint script using my limited knowledge, but i came across an issue, being if you end the shift input while the tween is still playing, it bugs your walkspeed as it would use the current speed value (being tweened) instead of the base speed value of the character.
what i'm doing right now is using the variable "wstarget" to define the character's base walkspeed, but i am afraid that might cause difficulties in the future if i want the wstarget variable to be changed by another script.
i thought of a possible remedy for this problem, being:
store the player's base walkspeed inside a stringvalue parented to the player's character model, and retrieve that value whenever they sprint
but i don't think that is the most efficient way of doing so

mb if this is a stupid question, i couldn't find answers anywhere and i really want to avoid technical debt
(im putting the script as its own message inside the thread because of discord character limits :p)

#
local player = game:GetService("Players")
local uis = game:GetService("UserInputService")
local ts = game:GetService("TweenService")
local humanoid = player.LocalPlayer.Character:WaitForChild("Humanoid")
local wstarget = humanoid.WalkSpeed -- the part im not sure where to store

uis.InputBegan:Connect(function(input, gp)
    local tweeninfo = TweenInfo.new(.5, Enum.EasingStyle.Sine, Enum.EasingDirection.In) 
    if input.KeyCode == Enum.KeyCode.LeftShift then
        wstarget = wstarget + 16
        local speedtable = {
            WalkSpeed = wstarget
        }    
        local tween = ts:Create(humanoid, tweeninfo, speedtable)
        print(wstarget)
        tween:Play()
    end
end)

uis.InputEnded:Connect(function(input, gp)
    local tweeninfo = TweenInfo.new(.3, Enum.EasingStyle.Sine, Enum.EasingDirection.In) 
    if input.KeyCode == Enum.KeyCode.LeftShift then
        wstarget = wstarget - 16
        local speedtable = {
            WalkSpeed = wstarget
        }    
        local tween = ts:Create(humanoid, tweeninfo, speedtable)
        print(wstarget)
        tween:Play()
    end
end)
#

i dont need help rewriting the script or anything, just direction on where to store the information

desert herald
drowsy flume
#

ohh actually now that i think about it

#

i could just use a remote event or something fired from the server

desert herald
drowsy flume
#

and then have the script update the variable when it recieves the event

desert herald
#

if you want to change it outside the script then maybe have 2 number values, one for walk speed and one for sprint speed? same-same thing at the end of the day 🤷

drowsy flume
#

where would i put the values? in the character model?

gilded trellisBOT
#

studio** You are now Level 1! **studio

desert herald
drowsy flume
#

okay

#

was just wondering if there was like a more efficient way or something

#

thanks for the help!!

desert herald
#

get it working first and if it gives you 10fps only then worry about efficiency Crazyeyes

drowsy flume
#

LOL

#

okay