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?
Store all the killbricks on a table and then just loop through each killbrick and set its brickcolor to red
wont it be easier with a localscript
(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)
I want it to be so it only works for the player who purchases the gamepass
also why is there a tweenservice in the script
Don’t want a smooth color change?
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
can you send it in a script? I dont feel comfortable downloading something from someone I dont really know
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)
Alright im about to test that out rn and ill tell you if it works or not
Thank you so much, now it works
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.