You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
I want to make a part that when you click it an remote event gets fired to give the player a point
What is the issue? Include screenshots / videos if possible!
The remoteEvent is not firing here is the script that fires the remote event:
And here is the local script that responds when the event gets fired:
script.Parent.OnClientEvent:Connect(function(plr,multiplied,Rebirths)
local Requirement = plr.leaderstats.RebirthCost.Value * multiplied
if plr.leaderstats.TimeWasted.Value >= Requirement then
print()
plr.leaderstats.Rebirths.Value += Rebirths
end
print("Worked")
end)
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
It didn’t help.
Changing things like leaderstats should be done by the server, as it is not replicated to other clients (or the server) if done on the client.
You should instead remove the local script you have and just have this as a server script inside the part:
script.Parent.ClickDetector.MouseClick:Connect(function(plr)
local Requirement = plr.leaderstats.RebirthCost.Value * 1
if plr.leaderstats.TimeWasted.Value >= Requirement then
print()
plr.leaderstats.Rebirths.Value += 1
end
print("Worked")
end)
I would also like to point out that it is good practice to use Instance:WaitForChild() when dealing with leaderstats depending on how your data is handled. If a player joins the game and clicks the part before their leaderstats have been created, the script will break.
You’ll have to provide us with information on how your BillboardGui is structured and also any code you have that is already modifying the BillboardGui if you’d like help with that.
The solution I provided still applies, but then also put this into a local script in StarterPlayer → StarterPlayerScripts.
local player = game:GetService("Players").LocalPlayer
local rebirthCost = player:WaitForChild("leaderstats"):WaitForChild("RebirthCost")
local part = workspace:WaitForChild("Part1")
local gui = part:WaitForChild("BillboardGui"):WaitForChild("TextLabel")
function UpdateLabel()
local cost = rebirthCost.Value * 1
gui.Text = "Cost "..cost.." TimeWasted Points"
end
UpdateLabel()
rebirthCost:GetPropertyChangedSignal("Value"):Connect(UpdateLabel)
This script essentially runs a function whenever the RebirthCost value changes. I do not think a RemoteEvent is necessary here unless the multiplier needs to be sent by the server.
Well the game is supposed to work like this:
1.You get points for every second (TimeWasted)
2.Once you get enough points you can go to the part to rebirth (i can make it as a gui but my friend @CrazyD4RKiller told me to make it as a part for some reason since he is the owner of the game)
3. And then you get more points per second after rebirthing
4.Repeat
Alright. Is there a reason the label would need to update other than when the cost changes, though? Logically it should only need to update if there is a difference in the cost.
That is exactly what it should be doing. As I said above, make sure the last code snippet I posted is located in a local script in StarterPlayer → StarterPlayerScripts.
local player = game:GetService("Players").LocalPlayer
local rebirthCost = player:WaitForChild("leaderstats"):WaitForChild("RebirthCost")
local part = workspace:WaitForChild("Part1")
local gui = part:WaitForChild("BillboardGui"):WaitForChild("TextLabel")
function UpdateLabel()
local cost = rebirthCost.Value * 1
gui.Text = "Cost "..cost.." TimeWasted Points"
end
UpdateLabel()
game.ReplicatedStorage.RemoteEvents.RemoteEvent.OnClientEvent:Connect(UpdateLabel) --Changed it because i don't want to make it so it fires it when the rebirthCost changes