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)
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)