"attempt to concatenate nil with string" even though the "nil" is a number casted to a string

script in the part (part is in serverstorage and the script is inside of the part):

script.Parent.ClickDetector.MouseClick:Connect(function(plr)
	local pointsEarnt = tostring(script.Parent.PointsValue.Value)
	local xpEarnt = tostring(script.Parent.XPValue.Value)
	plr.leaderstats.Cubes.Value += 1
	plr.leaderstats.Points.Value += script.Parent.PointsValue.Value
	game.ReplicatedStorage.PlaySoundForLocalPlayer:FireClient(plr)
	game.ReplicatedStorage.DisplayEarnCurrencyBox:FireClient(plr, xpEarnt, pointsEarnt)
	script.Parent:Destroy()
end)

clienthandler localscript (localscript is in starterplayerscripts):

game.ReplicatedStorage.DisplayEarnCurrencyBox.OnClientEvent:Connect(function(plr, earntXP, earntPoints)
	local randint = math.random(200,800)
	local newUI = game.ReplicatedStorage.TotalValue:Clone()
	newUI.Container.Position = UDim2.new(tonumber("0."..randint),0,1.25,0)
	newUI.Container.PointsEarnt.Text = "+"..earntPoints.." Points"
	newUI.Container.XPEarnt.Text = "+"..earntXP.." XP"
	newUI.Parent = game.Players.LocalPlayer.PlayerGui
	
	newUI.Container:TweenPosition(
		UDim2.new(tonumber("0."..randint), 0, tonumber("0."..math.random(400,600)), 0),
		Enum.EasingDirection.Out,
		Enum.EasingStyle.Bounce,
		1,
		true
	)
	task.wait(1)
	for i=0, 1, 0.01 do
		newUI.Container.PointsEarnt.TextTransparency = i
		newUI.Container.XPEarnt.TextTransparency = i
		task.wait()
	end
	newUI:Destroy()
end)

any help would be appreciated, i have also tried modifying only the pointsEarnt text but then the xpvalue would be used instead for the pointsEarnt

1 Like

plr doesn’t get passed through the remote event with OnClientEvent because you already have it through game:GetService("Players").LocalPlayer.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.