Tonumber() with TextBox isn't detecting text

I’ve been trying to make a dummy spawner but when I try the dummy spawns but the stats are not given.

Here is the console

Code:

Server Script


dummy = game:GetService("ReplicatedStorage"):WaitForChild("Extra").Dummy


script.Parent.MouseButton1Click:Connect(function()
	local plr = script.Parent.Parent.Parent.Parent.Parent
	task.wait()
	script.Parent.OnClick:FireClient(plr)
end)

script.Parent.TransferStuff.OnServerEvent:Connect(function(plr, hp, def, tshirt)
	local char = workspace:FindFirstChild(plr.Name)
	task.wait()
	local newdum = dummy:Clone()
	print(hp)
	
	task.wait()
	
	newdum.Parent = workspace
	newdum.Humanoid.MaxHealth = hp
	newdum.Humanoid.Health = dummy.Humanoid.MaxHealth
	newdum.Stats.Defense.Value = def
	newdum.Torso.TShirt.Texture = tshirt
	
	newdum:PivotTo(char.Torso:GetPivot() * CFrame.new(0, 0, -10))
	
end)

Local Script

script.Parent.OnClick.OnClientEvent:Connect(function(plr)
	
	script.Parent.ClickSound:Play()
	
	local hp = tonumber(script.Parent.Parent.Health.TextBox.Text)
	local def = tonumber(script.Parent.Parent.Defense.TextBox.Text)
	local tshirt = tonumber(script.Parent.Parent["T-Shirt"].TextBox.Text)
	
	task.wait()
	
	script.Parent.TransferStuff:FireServer(plr, hp, def, tshirt)
	
end)

Gui:
Screenshot 2024-07-24 031009

2 Likes

Print out the locations of the textboxes located inside of each tonumber() and see what it returns.

If it returns nil, that means getting the value of its .text value will also return nil since neither exist.

2 Likes

When I print the text it says what the text says
Same when i print the tonumber() result
But it doesnt let me change the dummy’s health

Could you give me the hierarchy in the explorer, or a video? I feel like there’s something I either don’t understand or missing because I don’t completely understand what the issue is.

1 Like

I just realized something, if I enter defense as 1 and health as 50 it sets the dummy’s defense to the health, 50?

Meaning its trying to set the maxhealth to “plr”

TShirt result is the defense one, too…

1 Like

I fixed it, new code

Sever Script

dummy = game:GetService("ReplicatedStorage"):WaitForChild("Extra").Dummy

script.Parent.TransferStuff.OnServerEvent:Connect(function(plr, hp, def, tshirt, something)
	local char = workspace:FindFirstChild(plr.Name)
	task.wait()
	local newdum = dummy:Clone()
	
	task.wait()
	
	newdum.Parent = workspace
	newdum.Humanoid.MaxHealth = def
	newdum.Humanoid.Health = dummy.Humanoid.MaxHealth
	newdum.Stats.Defense.Value = tshirt
	newdum.Torso.TShirt.Texture = something
	
	newdum:PivotTo(char.Torso:GetPivot() * CFrame.new(0, 0, -10))
	
end)

Local Script

script.Parent.MouseButton1Click:Connect(function()
	local plr = game.Players.LocalPlayer
	local something = nil
	
	script.Parent.ClickSound:Play()
	
	local hp = tonumber(script.Parent.Parent.Health.TextBox.Text)
	local def = tonumber(script.Parent.Parent.Defense.TextBox.Text)
	local tshirt = tonumber(script.Parent.Parent["T-Shirt"].TextBox.Text)
	
	task.wait()
	
	script.Parent.TransferStuff:FireServer(plr, hp, def, tshirt, something)
	
end)
2 Likes

Why are you sending the player argument when firing the event? It’s sent automatically, so in your case on the OnServerEvent connection the plr and hp parameters are both the same player firing the remote

script.Parent.TransferStuff:FireServer(hp, def, tshirt, something) -- Client
script.Parent.TransferStuff.OnServerEvent:Connect(function(plr, hp, def, tshirt, something) -- Server

On a side note: if you want your game to be mobile friendly, use the Activated event when clicking the button instead of MouseButton1Click

Edit: Haven’t seen that reply where you figured out, my bad

1 Like

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