How to make Sell place like in the Simulator Games?

So i am trying to make a Simulator game heres my recent script

in the part of --SellPart, i wanna make the Coins = to the Licks and then change their Licks into 0
and then update the text of both Coins and LP values inside the Gui so players see their Stats change
Their Lp converts into Coins

local datastore = game:GetService("DataStoreService")
local mydatastore = datastore:GetDataStore("DataStorage")

local playerTable = {}
local rp = game.ReplicatedStorage
game.Players.PlayerAdded:Connect(function(player)


	playerTable[player] = {Licks = 0,Coins = 0,Inventory = 0}
	local currentcoin = mydatastore:GetAsync("savedcoin"..player.UserId)
	local currentlp = mydatastore:GetAsync("savedlp"..player.UserId)
	local currentinventory = mydatastore:GetAsync("savedinventory"..player.UserId)


	playerTable[player].Licks = currentlp
	playerTable[player].Coins = currentcoin
	playerTable[player].Inventory = currentinventory
	wait(1)
	player.PlayerGui.Number.Frame.LP.Text = playerTable[player].Licks

end)
--Sell part
rp.onSell.OnServerEvent:Connect(function(player,key)
	if key == "sellpart" then
		playerTable[player].Coins = playerTable[player].Licks
		print("Coins Has Updated")
		wait(1)
		playerTable[player].Licks = 0
		print("LP has Updated")
		player.PlayerGui.Number.Frame.LP.Text = playerTable[player].Licks -- lick

		player.PlayerGui.Number.Frame.Coins.Text = playerTable[player].Coins -- coin
		
	end
end)

something like that,Now the Script in the part

local part = script.Parent

local rp = game.ReplicatedStorage

part.Touched:Connect(function(part)

if (part.Parent:FindFirstChildWhichIsA("Humanoid")) then

rp.onSell:FireServer("sellpart")

print("Touch")

end

end)

but that keeps giving me errors, FireServers can only be called from the client.
i wanna fix this error, so i wanna use Remote events when i am selling so i can update the Players
stats (Lp,Coins)

1 Like

FireServers can only be called from the client. is the error

1 Like
local Player = game.Players.LocalPLayer
local Char = Player.Character
local Humanoid = Char:FindFirstChild("Humanoid")

game.workspace.Part.Touched:Connect(function(hit)
   game.ReplicatedStorage.Event:FireClient()
   Player.leaderstats.Lp.Value - Lp.Value
   wait(0.1)
   Player.leaderstats.Coins.Value = Player.leaderstats.Lp.Value
end)

Hey.

The error pretty much explains everything.

You are trying to fire server through server, which is not possible using RemoteEvents.

What you ned to do is handle the .Touched function on server and use :FireClient() and update the coins.

or

You could be checking whenever the value gets changed on client and change the text depedning on it.

Hope I helped.

btw is it proper that you do the Player.leaderstats.Lp.Value thinggy there? inside the script?

btw how do i need to receive the FireClient at the main script?(Where the table located)

Uh, what’s main script?

Script that handles the selling or script that handles updating the text?

Also you don’t need to do FireClient().

You could use :GetPropertyChangedSignal(“Value”) for the LP value on client and change it whenever it changes.

The main script is the one with the table, and how to use this :GetPropertyChangeSignal(“Value”)?

What table?

function lpChanged()
      --change text to lp value here
end) 

Player.leaderstats.Lp:GetPropertyChangedSignal("Value"):connect(lpChanged)

make sure you use that script on client though.

Look at the top with the scrollable gui, with the data store

You don’t really need the rp.OnServerEvent signal, you can simply just write a server script in the part like this.

function sellPartTouched(hit)
      if hit.Parent ~= nil then
            local player = game.Players:GetPlayerFromCharacter(hit.Parent)¨
            if player ~= nil then
                  player.leaderstats.Lp.Value - Lp.Value
                  player.leaderstats.Coins.Value = Player.leaderstats.Lp.Value
            end
      end
end

script.Parent.Touched:connect(sellPartTouched)

Also, if it helped, please mark it as solution :heart:.

sorry to bother again, i tried this and edit some stuff like instead of LP i made it to Licks
and i got a incomplete function at the

player.leaderstats.Lp.Value - Lp.Value
player.leaderstats.Coins.Value = Player.leaderstats.Lp.Value

part

and it said leaderstats is not member of player somethin like that

player.leaderstats.Lp.Value = player.leaderstats.Lp.Value - Lp.Value
player.leaderstats.Coins.Value = Player.leaderstats.Lp.Value