The script that receives is:
game.ReplicatedStorage.UpgradeClicker.OnServerEvent:Connect(function(plr, number, cost)
if plr.leaderstats.Clicks >= cost then
local multiplyby = number + 1
local multiplier = plr:WaitForChild("Multiplier")
multiplier.Value = multiplyby
game:GetService("DataStoreService"):GetDataStore("Multiplier"):SetAsync(plr.UserId, multiplyby)
end
end)
The script that fires is:
local remote = game:GetService("ReplicatedStorage").UpgradeClicker
--[[script.Parent.MouseButton1Click:Connect(function()
if game.Players.LocalPlayer.leaderstats.Clicks.Value >= script.Parent.Cost.Value then
remote:FireServer(script.Parent.Name, script.Parent.Cost.Value)
else
print("Not enough clicks")
end
end)--]]
script.Parent.MouseButton1Click:Connect(function()
remote:FireServer(script.Parent.Name, script.Parent.Cost.Value)
end)
I keep getting the error:
attempt to index number with 'Value'
1 Like
Try this:
game.ReplicatedStorage.UpgradeClicker.OnServerEvent:Connect(function(plr, number, cost)
if plr.leaderstats.Clicks >= cost.Value then
local multiplyby = number + 1
local multiplier = plr:WaitForChild("Multiplier")
multiplier.Value = multiplyby
game:GetService("DataStoreService"):GetDataStore("Multiplier"):SetAsync(plr.UserId, multiplyby)
end
end)
local remote = game:GetService("ReplicatedStorage").UpgradeClicker
--[[script.Parent.MouseButton1Click:Connect(function()
if game.Players.LocalPlayer.leaderstats.Clicks.Value >= script.Parent.Cost.Value then
remote:FireServer(script.Parent.Name, script.Parent.Cost.Value)
else
print("Not enough clicks")
end
end)--]]
script.Parent.MouseButton1Click:Connect(function()
remote:FireServer(script.Parent.Name, script.Parent.Cost)
end)
1 Like
Found a problem you’d compared an instance:
plr.leaderstats.Clicks
To a number so change it to:
if plr.leaderstats.Clicks >= cost then
I’m pretty sure Clicks is a value, meaning it should be plr.leaderstats.Clicks.Value
Rather than
plr.leaderstats.Clicks
As you are indexing the value, not the object.
You are comparing an instance (Clicks) with a value, which is why you are getting this error. To fix this problem, you just need to add .Value to your server script. Also, you are adding a String with a number, which is a bigger problem. To fix this, you need to convert the String to a number by doing tonumber(number).
Here is your updated Server Script:
local DataStoreService = game:GetService("DataStoreService")
local MultiplierDataStore = DataStoreService:GetDataStore("Multiplier")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local UpgradeClicker = ReplicatedStorage:WaitForChild("UpgradeClicker")
UpgradeClicker.OnServerEvent:Connect(function(plr, number, cost)
if plr.leaderstats.Clicks.Value >= cost then
local multiplyby = tonumber(number) + 1
local multiplier = plr:WaitForChild("Multiplier")
multiplier.Value = multiplyby
MultiplierDataStore:SetAsync(plr.UserId, multiplyby)
end)