How do I make a value exclusive to a player

Hello, I am trying to make a script in which the player kicks a ball but the shot power value goes to everyone in the server. But I want to know how to make the value exclusive to the player. This is my code

local hitbox = game.Workspace.football.hitbox
local ball = hitbox.Parent

local rs = game:GetService("ReplicatedStorage")
local re1 = rs:FindFirstChild("FireHolding")
local re2 = rs:FindFirstChild("FireShotPower")
local re3 = rs:FindFirstChild("FireShotPower2")
local re4 = rs:FindFirstChild("FireRunning")

local dribbleSFX = hitbox["Football Dribble"]
local shotSFX = hitbox["Football Shoot"]

local shotpower = 1
local dribblepower = 25
local height = 35
local shotadd = 2

local runservice = game:GetService("RunService")
local holding = false

local deb = false

re4.OnServerEvent:Connect(function(Player, running)
	if running then

		if shotpower == 1 then
			dribblepower = 35
		end

		if shotpower > 1 then
			if shotpower < 2.75 then
				dribblepower = 70
				height = 0
			end

			if shotpower > 2.75 then
				dribblepower = 40
				height = 20
			end
		end
		shotadd = 2
	end

	if not running then

		if shotpower == 1 then
			height = 20
		end

		if shotpower > 1 then
			if shotpower < 2.75 then
				dribblepower = 60
				height = 0
			end

			if shotpower > 2.75 then
				dribblepower = 20
				height = 35
			end
		end

		if shotpower == 1 then
			dribblepower = 15
		end
		shotadd = 1.5
	end
end)

-- quadrant is 1 + 0.875
hitbox.Touched:Connect(function(hit)
	local hum = hit.Parent:FindFirstChild("Humanoid")
	if hum then
		local playerCharacter = hit.Parent
		local hrp = hum.Parent:FindFirstChild("HumanoidRootPart")
		local cf = hrp.CFrame
		local lookvector = cf.LookVector


		if deb == false then
			ball.AssemblyLinearVelocity = Vector3.new(lookvector.x * dribblepower * (shotpower * shotadd), 1 * (shotpower * height), lookvector.z * dribblepower * (shotpower * shotadd))

			if shotpower == 1 then
				dribbleSFX:Play()
			end
			deb = true
			if shotpower > 1 then
				re2:FireAllClients(shotpower)
				shotSFX.Volume = shotpower / 3
				shotSFX:Play()
			end
			wait(0.5)
			deb = false
		end
	end
end)

re1.OnServerEvent:Connect(function(player, newHoldingValue)
	holding = newHoldingValue
end)

while true do
	if holding == true then
		if shotpower < 3.5 then
			shotpower = shotpower + 0.06
			re3:FireAllClients(shotpower)
		end
	end

	if holding == false then
		shotpower = 1
		re3:FireAllClients(shotpower)
	end

	task.wait(0.0001)
end

I’ve tried using player number values but after 30 minutes I couldn’t get it working. And yes the script is a server script but this is clearly a problem. And i need to tinker it without messing up the remote events I have.

You are using a variable within the script to define “shotpower”:

local shotpower = 1

So any change will be for the entire script and every player.

A solution might be to add a NumberValue to each Player when they join.

When the script runs you can call up that NumberValue for each player and change it for each player individually.

Ive done this but when i use

local shotpower = instance.new("NumValue")
shotpower.Parent = char
shotpower.Value = 0

then use a remote event to transfer shotpower to a server script

if shotpower.Value == 0 then
shotpower.Value = 1
end

It argues that I tried to connect .Value with nil.

.Value with nil means that it cannot find “shotPower”.

Did you check for shotPower before trying to apply a value to it?

Something like:

if char then
	if char:FindFirstChild("shotPower") then
		if shotpower.Value == 0 then
			shotpower.Value = 1
		end	
	else
		print("Could not find shotPower")
	end
else
	print("Could not find char")
end

1 Like

To add onto what @mc7oof said: make sure you’re creating the NumberValue instance on the server, not the client. From your explanation, it sounds like you’re creating it on the client and then sending it as an argument through :FireServer().

1 Like

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