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

local in serverscriptservice is not defined?

hey everyone, im making a simulator game, but when i click it says the local i made is a nil value:

game.Players.PlayerAdded:Connect(function(player)
	print("leaderstats")
	local leaderstats = Instance.new('IntValue', player)
	leaderstats.Name = 'leaderstats'
			
	print("leaderstats")
	local IQ = Instance.new("IntValue", leaderstats)
	IQ.Name = "IQ"
	IQ.Value = 1000
end)


local ReplicatedStorage = game:GetService("ReplicatedStorage")

local ServerStorage = game:GetService("ServerStorage")

-- local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Toolnumber1clickEvent = Instance.new("RemoteEvent", ReplicatedStorage)
Toolnumber1clickEvent.Name = "Toolnumber1clickEvent"

     
local function onToolnumber1clickEventFired(player, number)
	IQ.Value = IQ.Value + 1
end

Toolnumber1clickEvent.OnServerEvent:Connect(onToolnumber1clickEventFired)



do you know why it says its a nil value? please tell me :)

1 answer

✓ Accepted answer

Try this.

game.Players.PlayerAdded:Connect(function(player)
    print("leaderstats")
    local leaderstats = Instance.new('IntValue', player)
    leaderstats.Name = 'leaderstats'


    print("leaderstats")
    local IQ = Instance.new("IntValue", leaderstats)
    IQ.Name = "IQ"
    IQ.Value = 1000
end)


local ReplicatedStorage = game:GetService("ReplicatedStorage")

local ServerStorage = game:GetService("ServerStorage")

-- local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Toolnumber1clickEvent = Instance.new("RemoteEvent", ReplicatedStorage)
Toolnumber1clickEvent.Name = "Toolnumber1clickEvent"


local function onToolnumber1clickEventFired(player, number)
	local IQ = player.leaderstats.IQ
    IQ.Value = IQ.Value + 1
end

Toolnumber1clickEvent.OnServerEvent:Connect(onToolnumber1clickEventFired)

The issue was you trying to trying to use a variable to create an IntValue, not modify it. By adding a new definition of IQ the script works.

1 comment

0

oh ok thank you so much :D you just made a nice game possible for roblox :)

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