ValueModifier Module, anti multiScript collision

Introduction

Hello there! I made a module script that focuses on changing numberProperties ie WalkSpeed and other stuff like numberValue Module its a simple module people with basic knowledge of module script should be able to replicate this

Alright so here’s the basic stuff and the main focus

  • AllowMultipleScripts so I’ve always noticed every time I make a combat system with punches that slows the player and sprinting so when you do both at the same time they always collide and break the Humanoid.WalkSpeed causes it to either go faster or slower than the original, it was very easy to implement but most people get stuck on this problem so I made sure to add it here you can disable it if you like

  • Debug not much really it just debugs and tell you if scripts are colliding forced set to false

Okay! that’s that now it’s time to know how to use it considering you don’t know :smile:

  1. First things first require the module!
    image_2023-06-16_004102623
    ill just put mine in ReplicatedStorage
    image_2023-06-16_004343321

  2. Next we call the setModifier function
    image_2023-06-16_004428221
    you need to make sure your calling the function using a colon “:” not a dot now lets put in the arguments

  3. Alright it works! but I want to revert it back to the original WalkSpeed to do that we need to use the function resetModifier
    image_2023-06-16_005632285
    with the following arguments
    image_2023-06-16_005720878

Okay so it works wonderfully that’s really all to it I hope this module helps you at the very least thank you for reading through this, If you have any advice please do tell I’m willing to listen

Sprint script using said Module -

local UserInputService = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TweenService = game:GetService("TweenService")
local Players = game:GetService("Players")

local ValueModifier = require(ReplicatedStorage.Libraries.ValueModifier)

local LocalPlayer = Players.LocalPlayer
local Character = LocalPlayer.Character
local Humanoid = Character.Humanoid

local NewAnim = Instance.new("Animation", script)
NewAnim.AnimationId = "rbxassetid://  your animationId  "
local Anim = Humanoid:LoadAnimation(script:WaitForChild("Animation"))

UserInputService.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.LeftShift then
		ValueModifier:setModifier(script, Humanoid, "WalkSpeed", 1.5)
		Anim:Play()
	end
end)

UserInputService.InputEnded:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.LeftShift then
		ValueModifier:resetModifier(script, Humanoid, "WalkSpeed")
		Anim:Stop()
	end
end)

Humanoid:GetPropertyChangedSignal("FloorMaterial"):Connect(function()
	if Humanoid.FloorMaterial ~= Enum.Material.Air and Humanoid.MoveDirection.Magnitude > 0 then
		TweenService:Create(workspace.CurrentCamera, TweenInfo.new(0.3), {FieldOfView = 80}):Play()
	else
		TweenService:Create(workspace.CurrentCamera, TweenInfo.new(0.7), {FieldOfView = 70}):Play()
	end
end)
4 Likes

So this is a state machine but instead of setting values, you set multipliers?

If you can stack multipliers, how would you remove a single multiplier?

If you’re sprinting and punching at the same time, and your punch stopped, you don’t want to reset all multipliers.

1 Like

I’m planning on making it stackable but rn it just blocks the 2nd scriptCaller

Yes if I reset all the multipliers it stacks well the multiplied numberProperty that’s why I just made it blocked the 2nd script from accessing the module it’s quite of a work around still figuring out how I would make it stackable without breaking though

Actually I have an idea maybe I’ll store every multiplier in a table and just re divide them 1 by 1 that might work I’ll do that tmrw