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 :)
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.