I’m currently working on a system in which an object has a 1/100 chance of activing a GUI which gives more tickets. The tickets add to the player’s leaderstats, however once they get any more or rejoin, the tickets they earned go away. Here is the localscript I have in StarterPlayerScripts to post the chat message and give the tickets:
workspace.InterpotWin.Changed:Connect(function()
local badgeservice = game:GetService("BadgeService")
local StarterGui = game:GetService("StarterGui")
wait()
if workspace.InterpotWin.Value > 0 then
if workspace.InterpotWin.Value >= 5000 then
StarterGui:SetCore("ChatMakeSystemMessage", {
Text = "[INTERPOT] " ..workspace.InterpotChancer.Value.." has just won the Interpot of " ..workspace.InterpotWin.Value.. "🎟",
Color = Color3.fromHSV(0.322222, 1, 1),
TextSize = 22
})
local plr = game.Players:WaitForChild(workspace.InterpotChancer.Value)
print(plr.leaderstats.Tickets.Value)
newtickets = math.round(plr.leaderstats.Tickets.Value + workspace.Interpot.Value)
plr.leaderstats.Tickets.Value = newtickets
workspace.InterpotWin.Value = 0
workspace.Save.Value = workspace.Save.Value + 1 --saves game
else
StarterGui:SetCore("ChatMakeSystemMessage", {
Text = "[INTERPOT] " ..workspace.InterpotChancer.Value.." has just won " ..workspace.InterpotWin.Value.. "🎟 off an Interpot Chance",
Color = Color3.fromHSV(0.322778, 1, 0.309804),
TextSize = 15
})
local plr = game.Players:WaitForChild(workspace.InterpotChancer.Value)
print(plr.leaderstats.Tickets.Value)
newtickets = math.round(plr.leaderstats.Tickets.Value + workspace.InterpotWin.Value)
print(newtickets)
plr.leaderstats.Tickets.Value = newtickets
workspace.InterpotWin.Value = 0
workspace.Interpot.Value = 5000
workspace.Save.Value = workspace.Save.Value + 1 --saves game
end end
end)
How do I make it so that the tickets given save to the player without vanishing once they collect more or rejoin?
You should check when the player grabs the collectable (on the server) it will then calculate on the server if they get that chance or not, then FireClient to that player with the result.
Of course changing the stats on the Server side too.
I currently have it so there is a server script that detects a value change that a client script changes. However, it seems as if this client script isn’t even changing this other value.
if workspace.InterpotWin, is a Value instance, and you are making the change on the client, then this Connect on the server will never fire.
Changes on the client, stay on the client, and are not replicated to the server.
You would need to either… Have the server make the change, or, have the client send a remote event to the server, telling the server to change the value.
Recommend to just stick with server because it’s easier, then send the information to Client.
That code you made would have worked in like 2015, but they added the FE (Filtering Enabled) which means you must use remotes to communicate with Client and Server.
I’ve tried to fire an event to the server, however the server only gets the player’s name.
CLIENT:
interpotTickets:FireServer(score * 30)
SERVER:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local interpotTickets = ReplicatedStorage:WaitForChild("interpotTickets")
function onWelcomePlayerFired(tix)
local plr = game.Players:WaitForChild(workspace.InterpotChancer.Value)
plr.leaderstats.Tickets.Value = math.round(plr.leaderstats.Tickets.Value + tix)
end
interpotTickets.OnServerEvent:Connect(function(tix)
onWelcomePlayerFired(tix)
end)
ERROR:
ServerScriptService.interpotAdd:6: attempt to perform arithmetic (add) on number and Instance
This is because the server always has the first parameter received as the player so the server knows what player the remote event was fired from. Instead, add the player to the parameters.