Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Script returns value as nil, how do I fix this?

Code:

local plr = game.Players.LocalPlayer
local uis = game:GetService("UserInputService")
local db = false
local trackerdb = false

wait(4)
local RE = script.Parent.Diref
uis.InputBegan:Connect(function(input, IsTyping)
	if IsTyping then return end
	if input.KeyCode == Enum.KeyCode.G then
	if db == true then return end
	db = true
	local tracker = Instance.new("IntValue")
	tracker.Parent = script
	tracker.Value = 0

	if tracker.Value == 0 then
		tracker.Value = 1
	else
		tracker.Value = 0
	end
	if plr.Data.Makiko.Value >= 40 and plr.Data.LeftMaina.Value >= 20 then
		RE:FireServer(tracker)
	end
	if tracker.Value == 1 then
		while true do
			if trackerdb == true then return end
			trackerdb = true
			if plr.Data.LeftMaina.Value >= 20 then
			plr.Data.LeftMaina.Value = plr.Data.LeftMaina.Value - 20
			end
			wait(2)
			trackerdb = false
		end
	end
	end
	
end)

In this local script, I tried to fire the value of tracker in a remove event, but when I tried to get the value of tracker in the real script, it says tracker is nil

2 comments

0

try printing it in the local script to see if the prob is from there

0

it wasnt sadly

1 answer

It's because you're firing the remote with the IntValue itself, which is a local instance visiblw only to you. You should fire its value instead, like RE:FireServer(tracker.Value), or refrain from using it and replace it with a normal variable.

1 comment

0

I've tried both of those, and both didn't fix anything, sadly, but fret not, I have found a solution

This discussion is preserved as it was. New answers, comments, and votes are closed.