Great Tutorial !! I need to learn as much from Activating Scripts from the UI/GUI Buttons. I always get confused which section we place the Script in.. under GUI's .. etc Thanks again. 😉
i am at the data-store part of your tycoon series (good series btw) and i wrote the "Savedata" script and changed the things that you said in the core, in the leaderstats but everytime i claim my tycoon instead of just letting me play but with a data store whenever i claim the tycoon the buttons are automaticly red and even if i have enough money to buy them its still red+it doesnt save i will reply to this comment with my core, leaderstats, save data scripts if you can help ill be really REALLY thankful , btw am a sub and your the best roblox studio tutorials youtuber you deserve at least 100k subs ngl
core: local Tycoon = script.Parent.Parent local mainItems = Tycoon:FindFirstChild("MainItems") local values = Tycoon:FindFirstChild("Values") local buttons = Tycoon:FindFirstChild("Buttons") local purchasedItems = Tycoon:FindFirstChild("PurcashedItems") local audio = Tycoon:FindFirstChild("Audio") local debounce = false local objects = {} local TweenService = game:GetService("TweenService") local random = Random.new() local BUILDING_ANIMATION_POSITION_OFFSET_AMOUNT = 2 local BUILDING_ANIMATION_PART_DELAY = 0.03 function hasProperty(instance, property) assert(typeof(instance) == "Instance") assert(typeof(property) == "string") local hasProperty = false pcall(function() local v = instance[property] hasProperty = true -- This line only runs if the previous line didn't error end) return hasProperty end function instanceListToPropertyDict(instances, propertyList) assert(typeof(instances) == "table") assert(typeof(propertyList) == "table") --[[Given a list of instances and a list of properties, construct a dictionary like so: dict = { [instance1] = {property1 = instance1.property1, property2 = instance1.property2, ...}, [instance2] = {property1 = instance2.property1, property2 = instance2.property2, ...}, ... }]] local dict = {} for _, instance in ipairs(instances) do local dictEntry = {} for _, property in pairs(propertyList) do assert(hasProperty(instance, property), string.format( [[Instance '%s' (a %s) doesn't have property '%s'.]], tostring(instance), instance.ClassName, property) ) dictEntry[property] = instance[property] end dict[instance] = dictEntry end return dict end function getDescendantsWhichAre(ancestor, className) assert(typeof(ancestor) == "Instance") assert(typeof(className) == "string") --[[Returns all descendants of ancestor which are of class className or a class that inherits from className]] local descendants = {} for _, descendant in pairs(ancestor:GetDescendants()) do if descendant:IsA(className) then table.insert(descendants, descendant) end end return descendants end function animateBuildingIn(buildingModel, tweenInfo) assert(typeof(buildingModel) == "Instance" and buildingModel.ClassName == "Model", string.format( "Invalid argument #1 to 'animateBuildingIn' (Model expected, got %s)", typeof(buildingModel) == "Instance" and buildingModel.ClassName or typeof(buildingModel) )) assert(typeof(tweenInfo) == "TweenInfo", string.format( "Invalid argument #1 to 'animateBuildingIn' (TweenInfo expected, got %s)", typeof(tweenInfo) )) --Collect BaseParts and original properties local parts = getDescendantsWhichAre(buildingModel, "BasePart") local originalProperties = instanceListToPropertyDict(parts, {"Transparency", "CFrame", "Color", "Size"}) local originalBasePartCFrame = buildingModel.PrimaryPart.CFrame --Make parts invisible and randomly move them for _, part in pairs(parts) do part.Transparency = 1 part.Color = Color3.fromRGB(255, 255, 255) part.Size = Vector3.new() local positionOffset = Vector3.new(random:NextNumber(-1, 1), random:NextNumber(-0.25, 1.75), random:NextNumber(-1, 1)) * BUILDING_ANIMATION_POSITION_OFFSET_AMOUNT local rotationOffset = CFrame.Angles(random:NextNumber(-math.pi, math.pi), random:NextNumber(-math.pi, math.pi), random:NextNumber(-math.pi, math.pi)) part.CFrame *= CFrame.new(positionOffset) * rotationOffset end --Tween them back to their original state, one at a time local lastTween --Return this so the caller can do animateBuilding(...):Wait() to wait for the animation to complete for _, part in pairs(parts) do local tween = TweenService:Create(part, tweenInfo, originalProperties[part]) lastTween = tween tween.Completed:Connect(function(playbackState) --Sometimes Tweens stop before reaching their goal properly. -- Make sure each Part is exactly how it was before. part.Transparency = originalProperties[part].Transparency part.CFrame = originalProperties[part].CFrame end) tween:Play() wait(BUILDING_ANIMATION_PART_DELAY) end return lastTween.Completed end mainItems.OwnerDoor.Door.Touched:Connect(function(hit) if values.OwnerValue.Value == nil then local player = game.Players:GetPlayerFromCharacter(hit.Parent) if player then if player:FindFirstChild("HasTycoon").Value == false then values.OwnerValue.Value = player mainItems.OwnerDoor.Title.SurfaceGui.TextLabel.Text = tostring(values.OwnerValue.Value).. "'s Tycoon" player:FindFirstChild("TycoonOwned").Value = Tycoon Tycoon.Parent.ClaimTycoon:Fire(Tycoon) end end end end) function playSound(object, soundID) if object:FindFirstChild("Sound") then return else local sound = Instance.new("Sound", object) sound.SoundId = soundID sound:Play() sound.Ended:Wait() sound:Destroy() end end if buttons then for i, v in pairs(buttons:GetChildren()) do spawn(function() if v:FindFirstChild("Button") then local newObject = purchasedItems:FindFirstChild(v.Object.Value) if newObject ~= nil then objects[newObject.Name] = newObject:Clone() newObject:Destroy() else v:Destroy() end if v:FindFirstChild("Dependency") then v.Button.Transparency = 1 v.Button.CanCollide = false v.Button.BillboardGui.Enabled = false coroutine.resume(coroutine.create(function() if Tycoon.Purchases:WaitForChild(v.Dependency.Value) then v.Button.Transparency = 0 v.Button.CanCollide = true v.Button.BillboardGui.Enabled = true end end)) end v.Button.Touched:Connect(function(hit) local player = game.Players:GetPlayerFromCharacter(hit.Parent) if player then if values.OwnerValue.Value == player then if v.Button.CanCollide == true then if player:FindFirstChild("leaderstats").Cash.Value >= v.Price.Value then player.leaderstats.Cash.Value -= v.Price.Value objects[v.Object.Value].Parent = Tycoon.Purchases playSound(v, audio.sound1.SoundId) v:Destroy() else playSound(v, audio.sound2.SoundId) end end end end end) end Tycoon.Purchases.ChildAdded:Connect(function(add) animateBuildingIn(Tycoon.Purchases:FindFirstChild(v.Object.Value), TweenInfo.new(1, Enum.EasingStyle.Elastic, Enum.EasingDirection.Out)):Wait() end) end) end end mainItems.CashCollector.Button.Touched:Connect(function(hit) local player = game.Players:GetPlayerFromCharacter(hit.Parent) if player ~= nil then if values.OwnerValue.Value == player then if player.Character.Humanoid.Health > 0 then if debounce == false then debounce = true mainItems.CashCollector.Button.BrickColor = BrickColor.new("Really red") player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + values.MoneyValue.Value values.MoneyValue.Value = 0 playSound(mainItems.CashCollector, audio.Cash2.SoundId) task.wait(0.8) mainItems.CashCollector.Button.BrickColor = BrickColor.new("Lime green") debounce = false end end end end end)
save data: local Players = game:GetService("Players") local dataStoreService = game:GetService("DataStoreService") local dataStore = dataStoreService:GetDataStore("MyTycoonDataStore") function saveData(player) local tycoon = player:FindFirstChild("TycoonOwned").Value local purchases = player:FindFirstChild("TycoonOwned").Value.Purchases local tycoonData = {} spawn(function() local success, Error = pcall(function() dataStore:SetAsync(player.UserId.."-Cash", player.leaderstats.Cash.Value) end) if not success then warn(Error) end end) for i, object in ipairs(purchases:GetChildren()) do table.insert(tycoonData, object.Name) end local success, Error = pcall(function() dataStore:SetAsync(player.UserId, tycoonData) end) if not success then warn(Error) end local newTycoon = game.ServerStorage:FindFirstChild(tycoon.Name):Clone() newTycoon.Parent = tycoon.Parent tycoon:Destroy() end local function Buttons(button) button.Button.CanCollide = false button.Button.Transparency = 1 button.Button.BillboardGui.Enabled = false end script.Parent.ClaimTycoon.Event:Connect(function(tycoon) local tycoonOwner = tycoon.Values.OwnerValue.Value local tycoonData local cashData spawn(function() local success, Error = pcall(function() cashData = dataStore:GetAsync(tycoonOwner.UserId.."-Cash") end) if not success then warn(Error) end if success and cashData then tycoonOwner.leaderstats.Cash.Value = cashData end end) local success, Error = pcall(function() tycoonData = dataStore:GetAsync(tycoonOwner.UserId) end) if not success then warn(Error) end if success and tycoonData then local tycoonClone = game.ServerStorage:FindFirstChild(tycoon.Name):Clone() tycoonClone.Parent = tycoon.Parent tycoonClone.Values.OwnerValue.Value = tycoon.Values.OwnerValue.Value tycoonOwner.TycoonOwned.Value = tycoonClone tycoonClone.MainItems.OwnerDoor.Title.SurfaceGui.TextLabel.Text = tycoon.MainItems.OwnerDoor.Title.SurfaceGui.TextLabel.Text tycoon:Destroy() tycoon = tycoonClone local purchasesFolder = tycoonClone:FindFirstChild("Purchases") local purchasedItemsFolder = tycoonClone:FindFirstChild("PurchasedItems") local buttonsFolder = tycoonClone:FindFirstChild("Buttons") for i, button in pairs(buttonsFolder:GetChildren()) do if button:FindFirstChild("Object") then local object = purchasedItemsFolder:FindFirstChild(button.Object.Value) if object and table.find(tycoonData, object.Name) then object.Parent = purchasesFolder Buttons(button) end end end end end) Players.PlayerRemoving:Connect(function(player) saveData(player) end) game:BindToClose(function() for i, player in pairs(game.Players:GetPlayers()) do saveData(player) end end)
Hi, in your tutorial on how to make a jumpscare you forgot to add sound. You said to put this script somewhere and i dont know where. You said i have to put it in the onDeath function but i still dont understand where. Can you make a tutorial?
This isnt connected to this video, but i seem to have some trouble with the "touching a part to play an animation" because i have a custom rig, Im making this game for a war and its in about 3 days. Could you help me out?
hey man, theres a bug on your tycoon series with the buttons. for example, if you have 200$ and a button costs $100, it will take double the money because the part doesnt go away fast enough. Is there a fix?
I've been working on a devious task: trying to make the Blox Fruits Dark Blade animation. Would you please make it for me? I have been working on it for a while now and i want to finish. Please help me!
ok i already made a lot of tycoons but i'm tired of doing it again and again who can i contact you because you know how to program well as i wrote you last time to try to make a Simulator, Race Clicker, Door and so on but I don't understand why you don't want to do it, you don't have to listen to me, but it's up to you how you want to do it. I was happy when I finally found a video where I can do Tycoon because people before you either didn't finish it or it didn't work so as you like please.
Hi there! I will be starting a lot of those series when I get back this August. Please don't think I was ignoring your suggestion, I'm just rather busy at the moment. Thank you for your suggestions though, have an amazing day!
rusty pls anwser to my other comment please bro i am a sub since 10k and i really love your content but i got stuck there please bro and happy 20k subs, hope you see that
Great Tutorial !! I need to learn as much from Activating Scripts from the UI/GUI Buttons.
I always get confused which section we place the Script in.. under GUI's .. etc
Thanks again. 😉
Do u know why this is happening I right the exact script in gui as he did and it’s not working
You are so underrated RUclipsr
Great video keep going🎉❤
Can you do a video about Daily reward systeme pls
nice tuts really helped me alot
Do u know why this is happening I write the exact script on gui and it doesn’t register
can make a vid how to use chat tag like vip chat tag or owner ? also love your vids
this + the tycoon series is gonna be sick
i am at the data-store part of your tycoon series (good series btw) and i wrote the "Savedata" script and changed the things that you said in the core, in the leaderstats but everytime i claim my tycoon instead of just letting me play but with a data store whenever i claim the tycoon the buttons are automaticly red and even if i have enough money to buy them its still red+it doesnt save i will reply to this comment with my core, leaderstats, save data scripts if you can help ill be really REALLY thankful , btw am a sub and your the best roblox studio tutorials youtuber you deserve at least 100k subs ngl
core: local Tycoon = script.Parent.Parent
local mainItems = Tycoon:FindFirstChild("MainItems")
local values = Tycoon:FindFirstChild("Values")
local buttons = Tycoon:FindFirstChild("Buttons")
local purchasedItems = Tycoon:FindFirstChild("PurcashedItems")
local audio = Tycoon:FindFirstChild("Audio")
local debounce = false
local objects = {}
local TweenService = game:GetService("TweenService")
local random = Random.new()
local BUILDING_ANIMATION_POSITION_OFFSET_AMOUNT = 2
local BUILDING_ANIMATION_PART_DELAY = 0.03
function hasProperty(instance, property)
assert(typeof(instance) == "Instance")
assert(typeof(property) == "string")
local hasProperty = false
pcall(function()
local v = instance[property]
hasProperty = true -- This line only runs if the previous line didn't error
end)
return hasProperty
end
function instanceListToPropertyDict(instances, propertyList)
assert(typeof(instances) == "table")
assert(typeof(propertyList) == "table")
--[[Given a list of instances and a list of properties, construct a dictionary like so:
dict = {
[instance1] = {property1 = instance1.property1, property2 = instance1.property2, ...},
[instance2] = {property1 = instance2.property1, property2 = instance2.property2, ...},
...
}]]
local dict = {}
for _, instance in ipairs(instances) do
local dictEntry = {}
for _, property in pairs(propertyList) do
assert(hasProperty(instance, property), string.format(
[[Instance '%s' (a %s) doesn't have property '%s'.]],
tostring(instance), instance.ClassName, property)
)
dictEntry[property] = instance[property]
end
dict[instance] = dictEntry
end
return dict
end
function getDescendantsWhichAre(ancestor, className)
assert(typeof(ancestor) == "Instance")
assert(typeof(className) == "string")
--[[Returns all descendants of ancestor which are of class className or a class that inherits from className]]
local descendants = {}
for _, descendant in pairs(ancestor:GetDescendants()) do
if descendant:IsA(className) then
table.insert(descendants, descendant)
end
end
return descendants
end
function animateBuildingIn(buildingModel, tweenInfo)
assert(typeof(buildingModel) == "Instance" and buildingModel.ClassName == "Model", string.format(
"Invalid argument #1 to 'animateBuildingIn' (Model expected, got %s)",
typeof(buildingModel) == "Instance" and buildingModel.ClassName or typeof(buildingModel)
))
assert(typeof(tweenInfo) == "TweenInfo", string.format(
"Invalid argument #1 to 'animateBuildingIn' (TweenInfo expected, got %s)",
typeof(tweenInfo)
))
--Collect BaseParts and original properties
local parts = getDescendantsWhichAre(buildingModel, "BasePart")
local originalProperties = instanceListToPropertyDict(parts, {"Transparency", "CFrame", "Color", "Size"})
local originalBasePartCFrame = buildingModel.PrimaryPart.CFrame
--Make parts invisible and randomly move them
for _, part in pairs(parts) do
part.Transparency = 1
part.Color = Color3.fromRGB(255, 255, 255)
part.Size = Vector3.new()
local positionOffset = Vector3.new(random:NextNumber(-1, 1), random:NextNumber(-0.25, 1.75), random:NextNumber(-1, 1)) * BUILDING_ANIMATION_POSITION_OFFSET_AMOUNT
local rotationOffset = CFrame.Angles(random:NextNumber(-math.pi, math.pi), random:NextNumber(-math.pi, math.pi), random:NextNumber(-math.pi, math.pi))
part.CFrame *= CFrame.new(positionOffset) * rotationOffset
end
--Tween them back to their original state, one at a time
local lastTween --Return this so the caller can do animateBuilding(...):Wait() to wait for the animation to complete
for _, part in pairs(parts) do
local tween = TweenService:Create(part, tweenInfo, originalProperties[part])
lastTween = tween
tween.Completed:Connect(function(playbackState)
--Sometimes Tweens stop before reaching their goal properly.
-- Make sure each Part is exactly how it was before.
part.Transparency = originalProperties[part].Transparency
part.CFrame = originalProperties[part].CFrame
end)
tween:Play()
wait(BUILDING_ANIMATION_PART_DELAY)
end
return lastTween.Completed
end
mainItems.OwnerDoor.Door.Touched:Connect(function(hit)
if values.OwnerValue.Value == nil then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player then
if player:FindFirstChild("HasTycoon").Value == false then
values.OwnerValue.Value = player
mainItems.OwnerDoor.Title.SurfaceGui.TextLabel.Text = tostring(values.OwnerValue.Value).. "'s Tycoon"
player:FindFirstChild("TycoonOwned").Value = Tycoon
Tycoon.Parent.ClaimTycoon:Fire(Tycoon)
end
end
end
end)
function playSound(object, soundID)
if object:FindFirstChild("Sound") then
return
else
local sound = Instance.new("Sound", object)
sound.SoundId = soundID
sound:Play()
sound.Ended:Wait()
sound:Destroy()
end
end
if buttons then
for i, v in pairs(buttons:GetChildren()) do
spawn(function()
if v:FindFirstChild("Button") then
local newObject = purchasedItems:FindFirstChild(v.Object.Value)
if newObject ~= nil then
objects[newObject.Name] = newObject:Clone()
newObject:Destroy()
else
v:Destroy()
end
if v:FindFirstChild("Dependency") then
v.Button.Transparency = 1
v.Button.CanCollide = false
v.Button.BillboardGui.Enabled = false
coroutine.resume(coroutine.create(function()
if Tycoon.Purchases:WaitForChild(v.Dependency.Value) then
v.Button.Transparency = 0
v.Button.CanCollide = true
v.Button.BillboardGui.Enabled = true
end
end))
end
v.Button.Touched:Connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player then
if values.OwnerValue.Value == player then
if v.Button.CanCollide == true then
if player:FindFirstChild("leaderstats").Cash.Value >= v.Price.Value then
player.leaderstats.Cash.Value -= v.Price.Value
objects[v.Object.Value].Parent = Tycoon.Purchases
playSound(v, audio.sound1.SoundId)
v:Destroy()
else
playSound(v, audio.sound2.SoundId)
end
end
end
end
end)
end
Tycoon.Purchases.ChildAdded:Connect(function(add)
animateBuildingIn(Tycoon.Purchases:FindFirstChild(v.Object.Value), TweenInfo.new(1, Enum.EasingStyle.Elastic, Enum.EasingDirection.Out)):Wait()
end)
end)
end
end
mainItems.CashCollector.Button.Touched:Connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player ~= nil then
if values.OwnerValue.Value == player then
if player.Character.Humanoid.Health > 0 then
if debounce == false then
debounce = true
mainItems.CashCollector.Button.BrickColor = BrickColor.new("Really red")
player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + values.MoneyValue.Value
values.MoneyValue.Value = 0
playSound(mainItems.CashCollector, audio.Cash2.SoundId)
task.wait(0.8)
mainItems.CashCollector.Button.BrickColor = BrickColor.new("Lime green")
debounce = false
end
end
end
end
end)
save data: local Players = game:GetService("Players")
local dataStoreService = game:GetService("DataStoreService")
local dataStore = dataStoreService:GetDataStore("MyTycoonDataStore")
function saveData(player)
local tycoon = player:FindFirstChild("TycoonOwned").Value
local purchases = player:FindFirstChild("TycoonOwned").Value.Purchases
local tycoonData = {}
spawn(function()
local success, Error = pcall(function()
dataStore:SetAsync(player.UserId.."-Cash", player.leaderstats.Cash.Value)
end)
if not success then
warn(Error)
end
end)
for i, object in ipairs(purchases:GetChildren()) do
table.insert(tycoonData, object.Name)
end
local success, Error = pcall(function()
dataStore:SetAsync(player.UserId, tycoonData)
end)
if not success then
warn(Error)
end
local newTycoon = game.ServerStorage:FindFirstChild(tycoon.Name):Clone()
newTycoon.Parent = tycoon.Parent
tycoon:Destroy()
end
local function Buttons(button)
button.Button.CanCollide = false
button.Button.Transparency = 1
button.Button.BillboardGui.Enabled = false
end
script.Parent.ClaimTycoon.Event:Connect(function(tycoon)
local tycoonOwner = tycoon.Values.OwnerValue.Value
local tycoonData
local cashData
spawn(function()
local success, Error = pcall(function()
cashData = dataStore:GetAsync(tycoonOwner.UserId.."-Cash")
end)
if not success then
warn(Error)
end
if success and cashData then
tycoonOwner.leaderstats.Cash.Value = cashData
end
end)
local success, Error = pcall(function()
tycoonData = dataStore:GetAsync(tycoonOwner.UserId)
end)
if not success then
warn(Error)
end
if success and tycoonData then
local tycoonClone = game.ServerStorage:FindFirstChild(tycoon.Name):Clone()
tycoonClone.Parent = tycoon.Parent
tycoonClone.Values.OwnerValue.Value = tycoon.Values.OwnerValue.Value
tycoonOwner.TycoonOwned.Value = tycoonClone
tycoonClone.MainItems.OwnerDoor.Title.SurfaceGui.TextLabel.Text = tycoon.MainItems.OwnerDoor.Title.SurfaceGui.TextLabel.Text
tycoon:Destroy()
tycoon = tycoonClone
local purchasesFolder = tycoonClone:FindFirstChild("Purchases")
local purchasedItemsFolder = tycoonClone:FindFirstChild("PurchasedItems")
local buttonsFolder = tycoonClone:FindFirstChild("Buttons")
for i, button in pairs(buttonsFolder:GetChildren()) do
if button:FindFirstChild("Object") then
local object = purchasedItemsFolder:FindFirstChild(button.Object.Value)
if object and table.find(tycoonData, object.Name) then
object.Parent = purchasesFolder
Buttons(button)
end
end
end
end
end)
Players.PlayerRemoving:Connect(function(player)
saveData(player)
end)
game:BindToClose(function()
for i, player in pairs(game.Players:GetPlayers()) do
saveData(player)
end
end)
Hi, in your tutorial on how to make a jumpscare you forgot to add sound. You said to put this script somewhere and i dont know where. You said i have to put it in the onDeath function but i still dont understand where. Can you make a tutorial?
hey nice vid can you make a slop system so like when character walk on a slop it tilts their character and makes it easier to walk on?
Can you make a video about how to make donations
Awesome!
This isnt connected to this video, but i seem to have some trouble with the "touching a part to play an animation" because i have a custom rig, Im making this game for a war and its in about 3 days. Could you help me out?
hey man, theres a bug on your tycoon series with the buttons.
for example, if you have 200$ and a button costs $100, it will take double the money because the part doesnt go away fast enough. Is there a fix?
it didint work
I've been working on a devious task: trying to make the Blox Fruits Dark Blade animation. Would you please make it for me? I have been working on it for a while now and i want to finish. Please help me!
Can you please do a tutorial on how to make a piggy like play menu like a play button
can u put the script in your comments because mine is not working and im not sure what doing wrong
ok i already made a lot of tycoons but i'm tired of doing it again and again who can i contact you because you know how to program well as i wrote you last time to try to make a Simulator, Race Clicker, Door and so on but I don't understand why you don't want to do it, you don't have to listen to me, but it's up to you how you want to do it. I was happy when I finally found a video where I can do Tycoon because people before you either didn't finish it or it didn't work so as you like please.
Hi there! I will be starting a lot of those series when I get back this August. Please don't think I was ignoring your suggestion, I'm just rather busy at the moment. Thank you for your suggestions though, have an amazing day!
@@rustysillyband thank you and also i want to thank for one thing i got Golden Crown for 100+ MAU on [Hacker Tycoon in 3:AM] thanks to you i got it :)
only one that works
it works on the two player test but not actual other players?
FIX THIS
@@Raggy11 dea
This didn’t work..
rusty pls anwser to my other comment please bro i am a sub since 10k and i really love your content but i got stuck there please bro
and happy 20k subs, hope you see that
Hi there! What's your other comment? Thank you for the support!