-
What do you want to achieve?
I want the player to be able to purchase a texture/skin by selecting a button at the top of their screen, deducting currency if they have the required amount. -
What is the issue?
For some odd reason, this ends up with negative numbers only sometimes. Usually about every 1/10 times. -
What solutions have you tried so far?
I have simplified the client script, such as removingif texture ~= floorTexture.Texture then
, but this is important to the script and does not fix the issue anyways.
Client Script (Handles the selection of the button, checks if the player has required points, Makes sure the player is not receiving the same texture/skin, applies texture/skin):
local player = game.Players.LocalPlayer
local floorTexture = workspace.Area.Platform.FloorTexture
local buyEvent = game.ReplicatedStorage.BuyFloorEvent
local whiteBlackCheckers = "rbxassetid://6625549840"
local redBlackCheckers = "rbxassetid://6625569786"
local polkaDots = "rbxassetid://6625160551"
local woodPlanks = "rbxassetid://6657105968"
local grass = "rbxassetid://6661754477"
local common = {whiteBlackCheckers, redBlackCheckers, woodPlanks, grass}
local uncommon = {polkaDots}
local tiers = {common, common, uncommon}
function onSelected()
if player.leaderstats.PopPoints.Value >= 250 then
local tier = tiers[math.random(1,#tiers)]
local texture = tier[math.random(1,#tier)]
if texture ~= floorTexture.Texture then
floorTexture.Texture = texture
buyEvent:FireServer()
end
end
end
script.Parent.MouseButton1Click:Connect(onSelected)
Server Script (Deducts points):
game.ReplicatedStorage.BuyFloorEvent.OnServerEvent:Connect(function(player)
player.leaderstats.PopPoints.Value = player.leaderstats.PopPoints.Value - 250
end)
Any help or feedback is appreciated.