Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

rebirth button is converting all coins to rebirths and rebirth noise is heard by all?

REPOSTED BECAUSE DIDNT GET ANSWER SORRY

this is the regular script inside a textbutton in a frame in a screengui

no errors

local Part = script.Parent
	Part.MouseButton1Click:Connect(function()
		local player = script.Parent.Parent.Parent.Parent.Parent
		if player then
			local leaderstats = player:WaitForChild("leaderstats")
			local Currency = leaderstats.Rebirths
			local Selling = leaderstats.Coins
			if (Selling.Value >= 1500) then
			Currency.Value = Currency.Value + Selling.Value + 1
			Selling.Value = 0
			player.leaderstats.Changes.Value = 0
			game.Workspace.clink.Playing = true
			wait(2)
			game.Workspace.clink.Playing = false
			end
		end
	end)

Idk how to get the sound "clink" to just play for the local player, because it would not play when inside the scripts Parent.

its also converting all coins to rebirths and adding 1, how fix?

1 answer

✓ Accepted answer

ok so uh, heres the thing

do not use normal scripts for guis. It is a bad practice. use local scripts instead since guis are locally designated as well.

to change stats, you will need a remote event.

how to fix this:

1.add a folder in replicatedstorage, (lets just name it GameRemotes) and then a RemoteFunction inside it called Rebirth.

2.put this script in the same place you placed your script, and make sure it is a local script.

local button = script.Parent
local rs = game:GetService("ReplicatedStorage")
local clink = game.Workspace:WaitForChild("clink")

button.MouseButton1Click:Connect(function()
	local player = game:GetService("Players").LocalPlayer
	rs:WaitForChild("GameRemotes"):WaitForChild("Rebirth"):InvokeServer()
	-- from here on, the script will wait until a server script i will place is done doing its thing then continue, this is to prevent a "sound plays before stats change" bug
	clink.Playing = true
	wait(2)
	clink.Playing = false
end)

3.add a normal script in serverscriptservice with the following code:

local Rebirth = game:GetService("ReplicatedStorage"):FindFirstChild("GameRemotes"):FindFirstChild("Rebirth")

Rebirth.OnServerInvoke:Connect(function(player)
	local lstats = player:FindFirstChild("leaderstats")
	local rebirths = lstats:FindFirstChild("Rebirths")
	local coins = lstats:FindFirstChild("Coins")
	if coins.Value < 1500 then return end
	rebirths.Value += 1 -- rebirths.Value = rebirths.Value + 1 but shorter
	coins.Value = 0
	lstats:FindFirstChild("Changes").Value = 0
end)

some links for further explanation:

OnServerInvoke Event

RemoteFunction

4 comments

0

got error from client side on line 7 in local script for InvokeServer is not valid child of Rebirth, and on server side a error for the sss script on line 3 saying OnServerInvoke isnt a child either

0

is it a RemoteFunction or a RemoteEvent? if it is a Remote Event, replace InvokeServer with FireServer, and replace OnServerInvoke with OnServerEvent

0

if you want it to be a remotefunction but rebirth event is a remote event (i explained why in this case you should use remote function), keep the script, and replace the rebirth remote event with a remote function with the same name

0

and also, i realised that what i did on my normal script was wrong. What i should've done was di Rebirth.OnServerInvoke = function(player) (you will need to remove the ")" at line 11)

This discussion is preserved as it was. New answers, comments, and votes are closed.