4_0gt
(4_0gt)
November 22, 2024, 4:34pm
1
I’m trying to make a shop sell system, but transfering the money to the leaderstats isn’t working.
the value “Money” isn’t actually the number but the player for some reason.
Client script:
script.Parent.InputBegan:Connect(function(obj)
if obj.UserInputType == Enum.UserInputType.MouseButton1 then
local target = game.Players.LocalPlayer.Inventory:FindFirstChild(script.Parent.Title.Text)
game.ReplicatedStorage.AddMoney:FireServer(game.Players.LocalPlayer,tonumber(target))
target:Destroy()
script.Parent:Destroy()
end
end)
Server script: (only important part)
game.ReplicatedStorage.AddMoney.OnServerEvent:Connect(function(plr,money)
plr.leaderstats.Money.Value = plr.leaderstats.Money.Value + money
local ui = Instance.new("ScreenGui")
ui.Parent = plr.PlayerGui
local text = Instance.new("TextLabel")
text.TextColor3 = Color3.fromRGB(170, 170, 170)
text.TextScaled = true
text.Font = Enum.Font.FredokaOne
text.BackgroundTransparency = 1
text.Position = UDim2.new(math.random(1,10)/10,0,1,0)
text.Parent = ui
text.Text = "+"..money
text.Size = UDim2.new(0, 200,0, 50)
local tweenp = game:GetService("TweenService"):Create(text,TweenInfo.new(2,Enum.EasingStyle.Sine),{Position = UDim2.new(text.Position.X,0,0.5,0)})
local tweent = game:GetService("TweenService"):Create(text,TweenInfo.new(2,Enum.EasingStyle.Linear),{TextTransparency = 1})
tweenp:Play()
tweent:Play()
game:GetService("Debris"):AddItem(ui,2)
end)
game.ReplicatedStorage.AddMoney:FireServer(tonumber(target))
When a client fires the server, the server automatically receives the player as the first argument, you don’t need to pass it. Replace that line with:
game.ReplicatedStorage.AddMoney:FireServer(tonumber(target))
4_0gt
(4_0gt)
November 22, 2024, 4:38pm
4
If i print it from the server side it returns nil for some reason now.
Did you try printing tonumber(target) on the client side first? It might not be the remote event where the problem is
4_0gt
(4_0gt)
November 22, 2024, 4:40pm
6
Done. And they both print nil.
4_0gt
(4_0gt)
November 22, 2024, 4:42pm
7
Oh no found the problem!:
In the LocalScript the target is set as :FindFirstChild(script.Parent.Title.**Text**)
Its supposed to be:
:FindFirstChild(script.Parent.Title).**Text**
4_0gt
(4_0gt)
November 22, 2024, 4:43pm
8
Just realised i cant set bold in code texts.
4_0gt
(4_0gt)
November 22, 2024, 4:44pm
9
Now it says “attempt to index nil with ‘Text’”
That’s probably because :FindFirstChild() couldn’t find what you were looking for
4_0gt
(4_0gt)
November 22, 2024, 4:45pm
11
Nevermind. Its still wrong i’m reading the code wrong
4_0gt
(4_0gt)
November 22, 2024, 4:46pm
12
Well we know the findfirstchild isn’t finding it now.
What are you trying to do? What are you trying to find?
4_0gt
(4_0gt)
November 22, 2024, 4:47pm
14
A Numbervalue in a folder located inside the player object.
4_0gt
(4_0gt)
November 22, 2024, 4:47pm
15
Its trying to get the value of that and then add that to the players balance.
Are you sure, that when the script runs, the number value will even be there?
4_0gt
(4_0gt)
November 22, 2024, 4:48pm
17
Yes i am.
It needs to be there, im even checking in the explorer
And how is script.Parent.Title that number value?
4_0gt
(4_0gt)
November 22, 2024, 4:49pm
19
It’s finding it perfectly its even deleting it after the click, its because of the remote event then.