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

local in serverscriptservice is not defined?

Asked by 5 years ago

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

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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.

0
oh ok thank you so much :D you just made a nice game possible for roblox :) sinbadxfan05 3 — 5y
Ad

Answer this question