It wont give me strenght when i click the keybind

this is the code also it wont show any errors

game.Players.PlayerAdded:Connect(function(plr)
local uis = game:GetService("UserInputService")
	plr:WaitForChild("leaderstats")

local _stats = plr.leaderstats
local strenght = _stats.Strenght
local Defense = _stats.Defense
local KI = _stats.KI
local Physic = _stats.Physic
local smulti = _stats:WaitForChild("smulti")
local kmulti = _stats:WaitForChild("kmulti")
local dmulti = _stats:WaitForChild("dmulti")
local pmulti = _stats:WaitForChild("pmulti")
local tp = _stats.TP
local add = game:GetService("ReplicatedStorage").Add.Value
local db = false
uis.InputBegan:Connect(function(input, gameProccesedEvent)
	if input.KeyCode == Enum.KeyCode.F then
		if db == false then
			db = true
			strenght.Value=strenght.Value + add.Value * smulti.Value
			wait(0.2)
			db = false
			end
		end
	
	if input.KeyCode == Enum.KeyCode.Q then
		if db == false then
			db = true
			KI.Value=KI.Value + add.Value * kmulti.Value
			wait(0.2)
			db = false
		end
	end
	if input.KeyCode == Enum.KeyCode.V then
		if db == false then
			db = true
			Defense.Value=Defense.Value + add.Value * dmulti.Value
			wait(0.2)
			db = false
		end
	end
	if input.KeyCode == Enum.KeyCode.Y then 
		if db == false then
			db = true
			Physic.Value=Physic.Value + add.Value * pmulti.Value
			wait(0.2)
			db = false
		end
	end
end)

while wait(0.2) do
	tp.Value = strenght.Value + Physic.Value + KI.Value + Defense.Value
	end
	end)

not a lot of info to go off of here, but if i had to assume anything it’d be that your trying to manipulate values in a localscript, which will not work. only server scripts can do that and trying to do that in a localscript will at best give you the illusion that you are changing the value.

you should research bindable and remote events as those allow for localscript to server script communication which is the only way for you to gain strenght via keypresses.

its a server script not local script

1 Like

why are you using userinputservice in a server script.

sorry im new to scripting im learning

still even if you are using a server script remote events allow for server scripts to take events from local scripts and that should allow you to run this code when a user presses a certain button.

be careful to make sure that the event is secure though as exploiters can simply call the event multiple times and make their strenght many time stronger.

idk how to secure remote events

by secure i mean simple checks like having a delay for when the ability can be activated and making it only activate when that delay is off.

that simple change will stop exploiters from infinitely giving themselves strenght by itself.

just add debounce into the script?

If this is a server script, server scripts can’t use UserInputService so it won’t work.

Instead use a local script to check if the player has pressed a key and then :Fire() a remote event that let’s a server script increase the value.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.