Help on RemoteEvents and Values [SOLVED]

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)

Not only it didn’t work but it made it so that it will print everything it touches including the map

E

I have solved it! i made a server script where instead of the leaderstats folder being in the player, i made it in the replicated storage then i made a gui where the localscript will count how much Points you have, then i only needed to add a single line of code for the orbies and i was done!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.