How do I get this to work?

I’m trying to get it so every time a part named SummonedPart spawns into the map, the player gets 1 Part in Workspace.

game:GetService('Players').PlayerAdded:Connect(function(player)
	for i,v in pairs(workspace:GetChildren()) do 
	if v.Name == "SummonedPart" then
			player.leaderstats["Parts in Workspace"].Value = player.leaderstats["Parts in Workspace"].Value + 1
		end
		end
end)

The Parts are Local, I just don’t know how to convert local parts into serverside .

Use a remote event to send a signal to a server script, so the server script can create a part.

i dont need a part serversided, I want the player to get the currency serversided.

Exactly, you could do that as well with remote events.

Example:

This you would put in your local script

local addValueEvent = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent") -- insert a remote event in Replicated Storage.

game:GetService('Players').PlayerAdded:Connect(function(player)
	for i,v in pairs(workspace:GetChildren()) do 
		if v.Name == "SummonedPart" then
			addValueEvent:FireServer()
		end
	end
end)

Server Side:

local addValueEvent = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent") -- insert a remote event in Replicated Storage. 

createPartEvent.OnServerEvent:Connect(function(player)
	player.leaderstats["Parts in Workspace"].Value = player.leaderstats["Parts in Workspace"].Value + 1
end)

then how do I give the player money with the remote?

Have an onserverevent in a server script handle that

Also are you spawning the SummonedPart locally or spawning it by the server?

im spawning it locally only. so all players don’t lag out

Then upon spawning your part fire your remote event and have the server give you the money

I just wrote an example for you in the previous post.

thanks :DD I modified it a bit

1 Like