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