Help on RemoteEvents and Values [SOLVED]

SOLVED

So Basicly im a Beginner Developer that is making a game about Merging spheres but the game seems boring because all you do is merge Spheres so i decided to try and make a Value that goes up by +1 everytime the player merges 2 spheres (that are the same) so that i can make upgrades for players that will help them through the game. Only problem is that i dont exacly know how to, i used the AI feature, looked up on youtube and dev forums and guess what? Nothing! So i need help with Remote Events and Values.

Scripts removed for reasons

1 Like

There are a few things here.

  1. You are editing the player’s value on the client. Anything changed on the client only changes for that client. You need to change it on the server for it to replicate.
  1. FireClient takes one arguement minimum and that is the Player object of the player to fire to. You can use the Players service’s GetPlayerFromCharacter function to check for a player’s touch, or some other way to get the player.
    Should look something like RemoteEvent:FireClient(player) and any other values to pass go after player as parameters.
1 Like

The remote event you using is on the client, it only works with the client, not the server, if it on the server, it will be 0 or nil

1 Like

Im not the smartest guy but this is what its giving me an error that doesn’t allow the script to progress:

Script(inside of the sphere):
local SS = game:GetService(“ReplicatedStorage”)
local MergeSound = workspace[“Music/Sounds”]:FindFirstChild(“MergeSound”)
local player = game.Players:GetPlayerFromCharacter() – What gives me the error

local part = script.Parent

part.Touched:Connect(function(hit)

	if hit.Name == "Orbie1" then
	game.ReplicatedStorage.MergeStatEvent:FireClient(player)
	MergeSound:Play()
		part:Destroy()
		hit:Destroy()

		local newPart = SS.Orbies.Orbie2:Clone()
		newPart.Parent = workspace
		newPart.Position = hit.Position
	end
end)

I am currently confused on what to do

Currently i made a server script for the Values:

– Script for creating leaderstats for the player

– Get the player’s character
local function onPlayerAdded(player)
local character = player.Character or player.CharacterAdded:Wait()
– Wait for the player’s humanoid to load
local humanoid = character:WaitForChild(“Humanoid”)
– Create leaderstats for the player
local leaderstats = Instance.new(“Folder”)
leaderstats.Name = “leaderstats”
leaderstats.Parent = player
– Create a value for the player’s money
local money = Instance.new(“IntValue”)
money.Name = “Merged”
money.Value = 0
money.Parent = leaderstats

game.ReplicatedStorage.MergeStatEvent.OnServerEvent:Connect(function()
	money.Value = money.Value + 1
end)

end

There is no local player, so you will have to add like local Players = game:GetService:("Players).

You can use this code instead of that, remote events is not your best bet.

local part = script.Parent

part.Touched:Connect(function(hit)

	
	if hit.Name == "Orbie1" then

		money.Value = money.Value + 1

		
		MergeSound:Play()
		part:Destroy()
		hit:Destroy()

		local newPart = SS.Orbies.Orbie2:Clone()
		newPart.Parent = workspace
		newPart.Position = hit.Position
	end
end)

That is how you get the player when they touched a part and using the Fire Client.

Not necessary, but you can use this:

It seems like the script works only for the merging part but now i gotta figure out how to get the leaderstats as the leaderstats dont appear, doing nothing in the process

local part = script.Parent

	part.Touched:Connect(function(hit)


		if hit.Name == "Orbie1" then
			local Players = game:GetService("Players")
			
			
			local Player = Players:GetPlayerFromCharacter(hit.Parent)

			if player then
				player.leaderstats.money.Value = player.leaderstats.money.Value + 1
			end


			MergeSound:Play()
			part:Destroy()
			hit:Destroy()

			local newPart = SS.Orbies.Orbie2:Clone()
			newPart.Parent = workspace
			newPart.Position = hit.Position
		end
	end)

I updated one of yours

Okay thanks! But now i gotta figure out how to make the leaderstats appear as it doesn’t appear… As im in roblox studio trying to figure out why.

Do you want them to make it saved?

Add a new script and called Leaderstats, and copy this and paste into the script. Put the script into ServiceScriptService

local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder", player)
	leaderstats.Name = "leaderstats"
	
	local NumberValue = Instance.new("NumberValue", leaderstats)
	NumberValue.Name = "money"
end)

Yeah, but i already fixed the problem by making a new leaderstat, but now it doesn’t seem like its giving me points on merging the spheres.

1 Like

Can you send me the script so I can see it?

This is the script right now:

game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new(“Folder”)
leaderstats.Name = “leaderstats”
leaderstats.Parent = player

local money = Instance.new("IntValue")
money.Name = "Merged"
money.Value = 0
money.Parent = leaderstats

end)

This is your updated code.

local part = script.Parent

	part.Touched:Connect(function(hit)


		if hit.Name == "Orbie1" then
			local Players = game:GetService("Players")
			
			
			local Player = Players:GetPlayerFromCharacter(hit.Parent)

			if player then
				player.leaderstats.Merged.Value = player.leaderstats.Merged.Value + 1
			end


			MergeSound:Play()
			part:Destroy()
			hit:Destroy()

			local newPart = SS.Orbies.Orbie2:Clone()
			newPart.Parent = workspace
			newPart.Position = hit.Position
		end
	end)

I tried and it did nothing, i will try to send some pictures of the script and they’r places

Capture

Capture1

Capture4

It doesn’t work because the value is an Integer/Int Value, It only accepts for Positive and Negative Numbers, you will have to replace the Instance.new(“IntValue”) to Instance.new(“NumberValue”). Here is your updated script for the leaderstats.

Replace that to this:

local money = Instance.new("NumberValue")
money.Name = "Merged"
money.Value = 0
money.Parent = leaderstats

Its still not doing anything, for a bit of context. What the player needs to do is push the sphere to the other one, when the sphere touches the other one then it will create a new variant and it WOULD give the value if it did anything.

Sorry for late reply but try this:

local part = script.Parent

	part.Touched:Connect(function(hit)

print(hit.Name)


		if hit.Name == "Orbie1" then
			local Players = game:GetService("Players")
			
			
			local Player = Players:GetPlayerFromCharacter(hit.Parent)

			if player then
				player.leaderstats.Merged.Value = player.leaderstats.Merged.Value + 1
			end


			MergeSound:Play()
			part:Destroy()
			hit:Destroy()

			local newPart = SS.Orbies.Orbie2:Clone()
			newPart.Parent = workspace
			newPart.Position = hit.Position
		end
	end)