Script changing part for everyone when not supposed to

What do I want to achieve?
I want it so when the player clicks a button, the part only changes for them.

What is the issue?
The parts changes for the whole server! I need it for the local player

I have no clue what is the problem.

local Num = 0
local id = 16906874

game:GetService("Players").PlayerAdded:Connect(function(client)
	client.CharacterAdded:Connect(function(character)
		client.PlayerGui:WaitForChild("PartEdit").Base.Green.MouseButton1Click:Connect(function()
			Num = 1
		end)
		client.PlayerGui:WaitForChild("PartEdit").Base.Yellow.MouseButton1Click:Connect(function()
			Num = 2
		end)
		client.PlayerGui:WaitForChild("PartEdit").Base.Purple.MouseButton1Click:Connect(function()
			Num = 0
		end)
		client.PlayerGui:WaitForChild("PartEdit").Base.Rainbow.MouseButton1Click:Connect(function()
			if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(client.UserId,id) then
				Num = 3
			else
				game:GetService("MarketplaceService"):PromptPurchase(client, id) 
			end
		end)

I would be happy if someone helps out.

1 Like

Normal scripts will change properties of your game on the server, you need to change parts of a LocalScript. But do note, LocalScripts in the workspace will not run, you need to put them in something like ReplicatedFirst or wherever else is most suitable for you.

You could use RemoteEvents to send the action to a specific player, then handle it with a LocalScript.

I did try this, but I have scripts in the parts that dont work when I use the local script

I did mention that you need to put it somewhere else, it won’t work if it is under workspace.

RemoteEvent | Roblox Creator Documentation read this!

You don’t need remote events for this. Simply put in in a local script. (Except for player added and character added, there’s no need for that, I assume that you only want to detect if the buttons are being clicked)

Basically,

And

And don’t forget to make a variable for LocalPlayer (‘client’).

I know what a RemoteEvent is lmao. What he is asking does not necessarily need that, I am simply telling him that he must put his LocalScripts somewhere other than the workspace in order for them to run.

Im sorry, it wasnt meant to tag you sorry :DD

Just

Use
a LocalScript

for this

and

set it in StarterCharacterScripts:

(Ignore my random formatting please)

local Num = 0
local id = 16906874

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local PlayerGui = Player:WaitForChild("PlayerGui")
local PartEdit = PlayerGui:WaitForChild("PartEdit")

Part.Edit.Base.Green.MouseButton1Click:Connect(function()
	Num = 1
end)

Part.Edit.Base.Yellow.MouseButton1Click:Connect(function()
	Num = 2
end)

Part.Edit.Base.Purple.MouseButton1Click:Connect(function()
	Num = 0
end)

Part.Edit.Base.Rainbow.MouseButton1Click:Connect(function()
	if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(Player.UserId, id) then
	    Num = 3
	else
	    game:GetService("MarketplaceService"):PromptPurchase(Player, id) 
    end
end)

I also do recommend separating your conditional statements so that it’s a bit more organized to read :thinking:

Hey! So everything works but, I have scripts in the part. those dont work

What do you mean by scripts in the Part? Couldn’t you just change the Part from the client standpoint instead?

surface and billboardguis, basically any interactive thing parented to an object in workspace is automatically server sided