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

Why will this FE script give me a nil value when played?

Asked by 5 years ago
Edited 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() 
    local Data = Instance.new("IntValue") 
    Data.Parent = script.Parent.Parent
    Data.Name = "Data" 
    local XP = Instance.new("IntValue") 
XP.Parent = script.Parent.Parent
    XP.Name = "XP" 
    XP.Value = 0
    local Level = Instance.new("IntValue") 
Level.Parent = script.Parent.Parent
    Level.Name = "Level"
    Level.Value = 1 
    local Tries = Instance.new("IntValue")
Tries.Parent = script.Parent.Parent
    Tries.Value = 10
    Tries.Name = "Tries"
    local ExCap = Instance.new("IntValue")
ExCap.Parent = script.Parent.Parent
    ExCap.Value = 500
    ExCap.Name = "ExCap"
    XP.Changed:connect(function() XP.Value,Level.Value,ExCap.Value) end)
end)



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

Basically XP is changed it will fire a Event called FireClient

Local script

game.Workspace.RemoteEvent.OnClientEvent:Connect(function(ExCap.Value,Level.Value,XP.Values)
        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

1 answer

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

It's because OnClientEvent doesn't really take player parameter, so do this instead on line 2:

game.Workspace.RemoteEvent.OnClientEvent:Connect(function(ExCap,Level,XP) --just remove the Player parameter you had there

Dont send like value objects to client, instead send their real values, so instead of sending XP, Level and ExCap send their values so XP.Value and same for other.

In your local script you can have everything the same just again don't compare XP.Value but instead compare just XP

Also Instance.new with parent argument is deprecated and ineffective so you should set a parent of an object after you set all properties, also it's Connect instead of connect.

0
Can you show me how this would look like? GGButNO_RE 61 — 5y
0
no sorry I can't rewrite the code for you that's not what this ebsite is for, I told you where your problem is and how to fix now you just have to apply it properly g1o2r3d4a5n6 350 — 5y
0
Ok thanks alot GGButNO_RE 61 — 5y
0
I changed the script a little bit 6 ^^ but i'm still have some errors. This is the server script error Workspace.Script:21: '=' expected near ')' this one is the Local script error error Players.powerdud.PlayerGui.LocalScript:1: ')' expected near '.' GGButNO_RE 61 — 5y
Ad

Answer this question