How do I make a gamepass in which it makes the parts for a color change?

Im trying to make a gamepass so whenever a player purchases it, it turns all the killbrick parts (each named killPart) into the color red. I’ve tried some different scripts but none of them worked. Can someone help?

3 Likes

Store all the killbricks on a table and then just loop through each killbrick and set its brickcolor to red

2 Likes

wont it be easier with a localscript

2 Likes

(works for everyone)

local marketplaceService = game:GetService("MarketplaceService")
local tweenService = game:GetService("TweenService")

local gamePassId = 0 -- your gamepass id

marketplaceService.PromptGamePassPurchaseFinished:Connect(function(player, passId, state)
	if state and passId == gamePassId then
		for _, object in workspace:GetDescendants() do
			if object:IsA("BasePart") and object.Name == "killPart" then
				tweenService:Create(object, TweenInfo.new(.3, Enum.EasingStyle.Sine, Enum.EasingDirection.Out), {
					Color = Color3.fromRGB(255, 89, 89)
				}):Play()
			end
		end
	end
end)
1 Like

I want it to be so it only works for the player who purchases the gamepass

1 Like

also why is there a tweenservice in the script

1 Like

Don’t want a smooth color change?

1 Like

No no, im trying to make it so whenever a player purchases the gamepass, all the parts named killPart change to the color red, its essentially so the player can know which part is deadly and which part is not. Thats my goal

1 Like

LocalTest1.rbxm (3,3 КБ)
try this

1 Like

can you send it in a script? I dont feel comfortable downloading something from someone I dont really know

1 Like

image


MarketplaceScript

local marketplaceService = game:GetService("MarketplaceService")
local replicatedStorage = game:GetService("ReplicatedStorage")
local players = game:GetService("Players")

local purchaseFinished = replicatedStorage.PurchaseFinished
local changeLoadingState = replicatedStorage.ChangeLoadingState

local gamePassId = 0 -- your gamepass id

players.PlayerAdded:Connect(function(player)
	player:SetAttribute("Loaded", false)
	
	repeat
		task.wait(.5)
	until player:GetAttribute("Loaded")
	
	if marketplaceService:UserOwnsGamePassAsync(player.UserId, gamePassId) then
		purchaseFinished:FireClient(player)
	end
end)

changeLoadingState.OnServerEvent:Connect(function(player)
	player:SetAttribute("Loaded", true)
end)

marketplaceService.PromptGamePassPurchaseFinished:Connect(function(player, passId, state)
	if state and passId == gamePassId then
		purchaseFinished:FireClient(player)
	end
end)

OnPurchaseFinished

local replicatedStorage = game:GetService("ReplicatedStorage")

local purchaseFinished = replicatedStorage.PurchaseFinished
local changeLoadingState = replicatedStorage.ChangeLoadingState

repeat
	task.wait(.5)
until game:IsLoaded()

task.wait()

changeLoadingState:FireServer()

purchaseFinished.OnClientEvent:Connect(function()
	for _, object in workspace:GetDescendants() do
		if object:IsA("BasePart") and object.Name == "killPart" then
			object.Color = Color3.fromRGB(255, 89, 89)
		end
	end
end)
1 Like

Alright im about to test that out rn and ill tell you if it works or not

1 Like

Thank you so much, now it works

1 Like

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