Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Help with changing stats, somehow a userdata value and not editable (FIlteringEnabled)?

I need this script to change the player's values, how ever and error appears that says:

16:18:37.775 - Workspace.Level:9: attempt to perform arithmetic on field 'DogeXP' (a userdata value)
16:18:37.777 - Stack Begin
16:18:37.778 - Script 'Workspace.Level', Line 9
16:18:37.779 - Stack End

Here is the script:

--ServerScript
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local LevelEvent = ReplicatedStorage:WaitForChild("LevelEvent")
LevelEvent.Name = "LevelEvent"
local Random = math.random(10,20)
 
local function onLevelFired(player)
	math.randomseed(tick())
	local Stats = player.Stats
	Stats.DogeXP.Value = Stats.XPNext.Value - Stats.DogeXP
	Stats.XPNext.Value = Stats.XPNext.Value * 5
	Stats.MaxHealth.Value = Stats.MaxHealth.Value + Random
	Stats.MaxHunger.Value = Stats.MaxHunger.Value + Random
	Stats.Speed.Value = Stats.Speed.Value + 0.5
	game.workspace[player.Name.."Dog"].RocketPropulsion.MaxSpeed = Stats.Speed.Value
	if player.Stats.Level.Value == 1 then
		game.workspace[player.Name.."Dog"].ShowName.txt.Text = player.Name.."'s Baby Doge [Level 1]"
		elseif player.Stats.Level.Value == 2 then
		game.workspace[player.Name.."Dog"].ShowName.txt.Text = player.Name.."'s Doge [Level 2]"
		elseif player.Stats.Level.Value == 3 then
		game.workspace[player.Name.."Dog"].ShowName.txt.Text = player.Name.."'s Normal Doge [Level 3]"
		elseif player.Stats.Level.Value == 4 then
		game.workspace[player.Name.."Dog"].ShowName.txt.Text = player.Name.."'s Growing Doge [Level 4]"
		elseif player.Stats.Level.Value == 5 then
		game.workspace[player.Name.."Dog"].ShowName.txt.Text = player.Name.."'s Flying Doge [Level 5 (Upgrade 1)]"
		elseif player.Stats.Level.Value == 6 then
		game.workspace[player.Name.."Dog"].ShowName.txt.Text = player.Name.."'s Faster Doge [Level 6]"
		elseif player.Stats.Level.Value == 7 then
		game.workspace[player.Name.."Dog"].ShowName.txt.Text = player.Name.."'s Cool Doge [Level 7]"
		elseif player.Stats.Level.Value == 8 then
		game.workspace[player.Name.."Dog"].ShowName.txt.Text = player.Name.."'s Powerful Doge [Level 8]"
		elseif player.Stats.Level.Value == 9 then
		game.workspace[player.Name.."Dog"].ShowName.txt.Text = player.Name.."'s Super Doge [Level 9]"
		elseif player.Stats.Level.Value == 10 then
		game.workspace[player.Name.."Dog"].ShowName.txt.Text = player.Name.."'s Super Duper Doge [Level 10 (Upgrade 2)]"
		elseif player.Stats.Level.Value == 11 then
		game.workspace[player.Name.."Dog"].ShowName.txt.Text = player.Name.."'s Extreme Doge [Level 11]"
		elseif player.Stats.Level.Value == 12 then
		game.workspace[player.Name.."Dog"].ShowName.txt.Text = player.Name.."'s Amazing Doge [Level 12]"
		elseif player.Stats.Level.Value == 13 then
		game.workspace[player.Name.."Dog"].ShowName.txt.Text = player.Name.."'s Super Doge [Level 13]"
		elseif player.Stats.Level.Value == 14 then
		game.workspace[player.Name.."Dog"].ShowName.txt.Text = player.Name.."'s EPIC Doge [Level 14] (Upgrade 3)"
		elseif player.Stats.Level.Value == 15 then
		game.workspace[player.Name.."Dog"].ShowName.txt.Text = player.Name.."'s LEGENDARY Doge [Level 15] (Max Upgrade (4), Max Level)"
	end
	end
LevelEvent.OnServerEvent:Connect(onLevelFired)

2 answers

✓ Accepted answer

On line 10 doge XP doesn't have a ".Value" after it!

--ServerScript
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local LevelEvent = ReplicatedStorage:WaitForChild("LevelEvent")
LevelEvent.Name = "LevelEvent"
local Random = math.random(10,20)

local function onLevelFired(player)
    math.randomseed(tick())
    local Stats = player.Stats
    Stats.DogeXP.Value = Stats.XPNext.Value - Stats.DogeXP -- < Right Here needs a .Value
    Stats.XPNext.Value = Stats.XPNext.Value * 5

6 comments

0

Thats true

0

Oh. Thanks!

0

No problem!

0

If he used filtering enabled doesn't he need to call the event??

0

It's in a server script so he doesn't need to

0

I already called the event anyway.

When using filtering enabled and remoteEvents its very important that you know how they communicate so the client calls the server(your level script) and vice versa Here is the other script you needed to have

--Client Script(Local Script)
local rs = game:GetService("ReplicatedStorage")
local remoteEvent = rs:WaitForChild("LevelEvent")
remoteEvent:FireAllClients()

There are other ways to fire a remoteEvent

remoteEvent:FireClient()
remoteEvent:FireServer()

Hopefully this helped! Please submit this answer

This discussion is preserved as it was. New answers, comments, and votes are closed.