Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 5 years ago

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

0
try printing it in the local script to see if the prob is from there starmaq 1290 — 5y
0
it wasnt sadly xXKingCool258Xx 39 — 5y

1 answer

Log in to vote
0
Answered by
Amiaa16 3227 Moderation Voter Community Moderator
5 years ago

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.

0
I've tried both of those, and both didn't fix anything, sadly, but fret not, I have found a solution xXKingCool258Xx 39 — 5y
Ad

Answer this question