What type of script would I need for the RemoteEvent?

Would I need a LocalScript, since MouseButton1Click or anything to detect player input is local? Right now, all I have is a RemoteEvent, inside ReplicatedStorage, no script or anything because I’m not sure which kind of script I would need. Additionally, If I use a LocalScript, then I won’t be able to update the leaderboard because thats the server (Right?)?

3 Likes

So if u want to send information from client to server you need to put in local script

local plr = game.Players.LocalPlayer
game.ReplicatedStorage.YourEvent:FireServer(plr,Stuffyousend,anotherstuffyousend)

and somewhere a normal script with

game.ReplicatedStorage.YourEvent.OnServerEvent:Connect(function(player,stuffyousend,anotherstuffyousend)
    print(stuffyousend,anotherstuffyousend)
end)
2 Likes

u can also print player from script to see who send it

you would do something like this

-- Local script
script.Parent.MouseButton1Click:Connect(function()
    game.ReplicatedStorage.Event:FireServer()
end)

-- Server script
game.ReplicatedStorage.Event.OnServerEvent:Connect(function()
    print("Fired!") -- print your stuff here
end)
1 Like

So I don’t modify the LocalScript that you just said, I just modify the ServerScript to do what I want it to, right?

yes, you would fire your function on the localscript and do whatever you want on the serverscript

The LocalScript goes in StarterGui under the TextButton that is being pressed right, then it fires the ReplicatedStorage event?

Edit: i meant replicated storage, i made a typo :slight_smile:

yes exactly and server script takes the info with .OnServerEvent

for example if i where to create a clicker game. and i wanted to add clicks, you would do this

-- local script inside the button
script.Parent.MouseButton1Click:Connect(function()
    game.ReplicatedStorage.RemoteEvent:FireServer()
end)

-- server script in SSS
game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player)
    player.leaderstats.Points.Value += 1
end)

the difference between fireserver and fireclient is fireserver is for the player server and client for the actually player if that makes sense

1 Like

What does replicated storge do then? If the script (and LocalScript) go in SSS and StarterGui? wait sss refers to serverscriptservice right?

replicated storage holds the event. Its the remoteevents parent.

yes SSS is serverscriptservice

Nope, didn’t work.

I have 3 scripts, two of which you said, and the other 1 creates the leaderboard.

-- Creates leaderboard

local Players = game:GetService("Players")

local function leaderboardSetup(player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player

	local points = Instance.new("IntValue")
	points.Name = "Splits"
	points.Value = 0
	points.Parent = leaderstats
end

Players.PlayerAdded:Connect(leaderboardSetup)

Edit: I have it working now! Ty so much! I’ve been struggling to do this. Quick question, is there a good way to save this?

hmmm i think ik the problem.
try this in the local script:

script.Parent.MouseButton1Click:Connect(function()
    game.ReplicatedStorage.RemoteEvent:FireServer()
    script.Parent.Active = false
    wait(1)
    script.Parent.Active = true
end)

i forgot to mention that you would have to put active to make sure the script is activated

I’ve already added a debounce function of my own.

is this script ok?

local debounce = false

script.Parent.MouseButton1Click:Connect(function()
	if debounce == false then
		game.ReplicatedStorage.Remote:FireServer()
		debounce=true
		wait(1.4) -- To fit how I need it
		debounce=false
	end
end)

1.4 seconds because thats (roughly) how long I need the player to wait before they can do it again.

yes, that should all work fine.

Hey @Icy7812! I know this topic has been resolved, but do you know a way to script so that if a user owns a gamepass, it (in this case) adds extra points to the leaderboard for the player?

there is, but i would not prefer to use gamepasses to add extra points. If you want players to buy multiple times. I would prefer devproducts.

Yeah, but the gamepass is sort of like a “Vip” or premium gamepass, it is supposed to be a one time purchase. Maybe I could add both eventually, but for now just gamepasses.

Well if your where to do something like that, do this:

-- local script inside game pass but button
local id = 1 -- game pass id here

script.Parent.MouseButton1Click:Connect(function()
    game.MarketplaceService:PromptGamePassPurchase(game.Players.LocalPlayer, id)
end)


-- Server script in SSS
local id = 1 -- id here

game.MarketplaceService.PromptGamePassPurchaseFinished:Connect(function(player)
    player.leaderstats.Points.Value += 10
end)

game.Players.PlayerAdded:Connect(function(player)
    if game.MarketplaceService:UserOwnsGamePassAsync(player.UserId, id) then
       player.leaderstats.Points.Vlaue += 10
    end
end)

So this would add 10 points every time the player joins?