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

Why does the FE script go nil when it is played?

Asked by 5 years ago

I have this FE script that goes nil when it is played. This is the error 20:42:48.509 - Players.powerdud.PlayerGui.LocalScript:2: attempt to index local 'XP' (a nil value) I don't understand why this doesn't work. If someone could help me it would be much appreciated.This is my code

Server script

game.Players.PlayerAdded:connect(function(Player) 
    local Data = Instance.new("IntValue",Player) 
    Data.Name = "Data" 
    local XP = Instance.new("IntValue",Data) 
    XP.Name = "XP" 
    XP.Value = 0
    local Level = Instance.new("IntValue",Data) 
    Level.Name = "Level"
    Level.Value = 1 
    local Tries = Instance.new("IntValue",Data)
    Tries.Value = 10
    Tries.Name = "Tries"
    local ExCap = Instance.new("IntValue",Data)
    ExCap.Value = 500
    ExCap.Name = "ExCap"
    XP.Changed:connect(function() XPChange(Player,XP,Level,ExCap) end)
end)



function XPChange(Player, XP, Level, ExCap)
    game.Workspace.RemoteEvent:FireClient(Player,ExCap,Level,XP)
    end 

Basically XP is changed it will fire a Event called FireClient

Local script

game.Workspace.RemoteEvent.OnClientEvent:Connect(function(Player,ExCap,Level,XP)
        if XP.Value >= ExCap.Value then
        if Level.Value < 100 then
            Level.Value = Level.Value + 1;
            XP.Value = XP.Value-ExCap.Value;
            ExCap.Value = ExCap.Value * 2;
        end
    end
    if Level.Value == 100 and XP.Value ~= 0 then
        XP.Value = 0;
end
end)

When XP rises more than ExCap, XP will subtract from ExCap

Answer this question