Hello all,
I am building a Castle Tycoon where you can buy expansion packs that will unlock specialty buttons. The gamepass effects will show up if you claim the base and already own the gamepass, but the player may want to buy the gamepass after owning the base and upgrading a few things. In this case, the buttons will not show up.
Here is the script:
local Market = game:GetService('MarketplaceService')
local gamePassId = 16624321
-- give player a trail
local function makeAPartsAppear(player)
local function partsAppear()
script.Parent.Parent.Parent.Part1.Transparency = 0
script.Parent.Parent.Parent.Part2.Transparency = 0
script.Parent.Parent.Parent.Part3.Transparency = 0
script.Parent.Parent.Parent.Part4.Transparency = 0
script.Parent.Parent.Parent.Part5.Transparency = 0
script.Parent.Parent.Parent.Part6.Transparency = 0
script.Parent.Parent.Parent.Part1.CanCollide = true
script.Parent.Parent.Parent.Part2.CanCollide = true
script.Parent.Parent.Parent.Part3.CanCollide = true
script.Parent.Parent.Parent.Part4.CanCollide = true
script.Parent.Parent.Parent.Part5.CanCollide = true
script.Parent.Parent.Parent.Part6.CanCollide = true
for i, button in ipairs(player:FindFirstChild('Base').Value.Buttons.ArchitectButtons:GetChildren()) do
button.Head.Transparency = 0
button.Head.CanCollide = true
button.Unlocked.Value = true
end
end
game.StarterGui.ScreenGui.ShopScreen.GamePassFrame.TextButton1.MouseButton1Click:Connect(partsAppear)
-- give the players character a trail immediately
if player then
partsAppear()
end
end
-- function to give the player their gamepass effect when they purchase in-game
local function purchaseComplete(player, purchaseId, purchaseSuccess)
if purchaseSuccess == true and purchaseId == gamePassId then
makeAPartsAppear()
end
end
Market.PromptGamePassPurchaseFinished:Connect(purchaseComplete)
The script is located inside of ServerScriptService. If you need any more information, just let me know. I appreciate any help :-).
2 Likes
Hmm. It doesn’t work, even though both print statements are running.
Here is the new code:
local Market = game:GetService('MarketplaceService')
local gamePassId = 16624321
-- give player a trail
local function makeAPartsAppear(player)
print('wudup')
local function partsAppear()
player:FindFirstChild('Base').Value.Part1.Transparency = 0
player:FindFirstChild('Base').Value.Part2.Transparency = 0
player:FindFirstChild('Base').Value.Part3.Transparency = 0
player:FindFirstChild('Base').Value.Part4.Transparency = 0
player:FindFirstChild('Base').Value.Part5.Transparency = 0
player:FindFirstChild('Base').Value.Part6.Transparency = 0
player:FindFirstChild('Base').Value.Part1.CanCollide = true
player:FindFirstChild('Base').Value.Part2.CanCollide = true
player:FindFirstChild('Base').Value.Part3.CanCollide = true
player:FindFirstChild('Base').Value.Part4.CanCollide = true
player:FindFirstChild('Base').Value.Part5.CanCollide = true
player:FindFirstChild('Base').Value.Part6.CanCollide = true
for i, button in ipairs(player:FindFirstChild('Base').Value.Buttons.ArchitectButtons:GetChildren()) do
button.Head.Transparency = 0
button.Head.CanCollide = true
button.Unlocked.Value = true
end
end
game.PlayerGui.ScreenGui.ShopScreen.GamePassFrame.TextButton1.MouseButton1Click:Connect(partsAppear)
-- give the players character a trail immediately
if player then
print('eyyy')
partsAppear()
end
end
-- function to give the player their gamepass effect when they purchase in-game
local function purchaseComplete(player, purchaseId, purchaseSuccess)
if purchaseSuccess == true and purchaseId == gamePassId then
makeAPartsAppear(player)
end
end
Market.PromptGamePassPurchaseFinished:Connect(purchaseComplete)
How can I access parts in the workspace from a script in ServerScriptService, without using game.Workspace? I think that might be the problem.
1 Like
You’re also referencing the game’s PlayerGui
, The game doesn’t have a PlayerGui, only a StarterGui
Try this:
local Market = game:GetService('MarketplaceService')
local gamePassId = 16624321
-- give player a trail
local function makeAPartsAppear(player)
print('wudup')
local function partsAppear()
player:FindFirstChild('Base').Value.Part1.Transparency = 0
player:FindFirstChild('Base').Value.Part2.Transparency = 0
player:FindFirstChild('Base').Value.Part3.Transparency = 0
player:FindFirstChild('Base').Value.Part4.Transparency = 0
player:FindFirstChild('Base').Value.Part5.Transparency = 0
player:FindFirstChild('Base').Value.Part6.Transparency = 0
player:FindFirstChild('Base').Value.Part1.CanCollide = true
player:FindFirstChild('Base').Value.Part2.CanCollide = true
player:FindFirstChild('Base').Value.Part3.CanCollide = true
player:FindFirstChild('Base').Value.Part4.CanCollide = true
player:FindFirstChild('Base').Value.Part5.CanCollide = true
player:FindFirstChild('Base').Value.Part6.CanCollide = true
for i, button in ipairs(player:FindFirstChild('Base').Value.Buttons.ArchitectButtons:GetChildren()) do
button.Head.Transparency = 0
button.Head.CanCollide = true
button.Unlocked.Value = true
end
end
player.PlayerGui.ScreenGui.ShopScreen.GamePassFrame.TextButton1.MouseButton1Click:Connect(partsAppear)
-- give the players character a trail immediately
if player then
print('eyyy')
partsAppear()
end
end
-- function to give the player their gamepass effect when they purchase in-game
local function purchaseComplete(player, purchaseId, purchaseSuccess)
if purchaseSuccess == true and purchaseId == gamePassId then
makeAPartsAppear(player)
end
end
Market.PromptGamePassPurchaseFinished:Connect(purchaseComplete)
1 Like
Okay, the functions are running but the buttons are not appearing (in partsAppear()). I don’t know what I’m doing wrong.
Highlighted are (a) the parts that need to be turned transparent and (b) the script in serverscriptservice.
1 Like
Are you sure you referenced the Value
right? If you’re wanting to change the Part properties, you can just simply do
player:FindFirstChild('Base').Part1.Transparency = 0
player:FindFirstChild('Base').Part2.Transparency = 0
player:FindFirstChild('Base').Part3.Transparency = 0
player:FindFirstChild('Base').Part4.Transparency = 0
player:FindFirstChild('Base').Part5.Transparency = 0
player:FindFirstChild('Base').Part6.Transparency = 0
player:FindFirstChild('Base').Part1.CanCollide = true
player:FindFirstChild('Base').Part2.CanCollide = true
player:FindFirstChild('Base').Part3.CanCollide = true
player:FindFirstChild('Base').Part4.CanCollide = true
player:FindFirstChild('Base').Part5.CanCollide = true
player:FindFirstChild('Base').Part6.CanCollide = true
1 Like
Hm, that simply gives the error:
Also, I forgot to show the ‘Base’ property, this might help:
Oh it’s an ObjectValue
-
Couldn’t you just reference the other Parts in the workspace
? I think an ObjectValue
can only hold just 1 Object, and not its descendants
1 Like
If its an object value you need to do this
player:FindFirstChild('Base').Value.Part5.CanCollide = true
Thanks, I’ll take your word for it. The reason I can’t use game.workspace.ect is that there will be multiple players, with multiple bases.