here is my script and i wanna remove the text and only have it display an image of the pet i got.
local plr = game.Players.LocalPlayer local open = plr:WaitForChild('OpenValue') while wait(0.1) do if open.Value == "Open" then wait(.2) script.Parent.Visible = true wait(.2) script.Parent.Rotation = 3 script.tic:Play() wait(.2) script.Parent.Rotation = -3 script.tic:Play() wait(.2) script.Parent.Rotation = 3 script.tic:Play() wait(.2) script.Parent.Rotation = -3 script.tic:Play() wait(.2) script.Parent.Rotation = 4 script.tic:Play() wait(.2) script.Parent.Rotation = -4 script.tic:Play() wait(.2) script.Parent.Rotation = 5 script.tic:Play() wait(.2) script.Parent.Rotation = -5 script.tic:Play() wait(.2) wait(.2) script.Parent.Rotation = 6 script.tic:Play() wait(.2) script.Parent.Rotation = -6 script.tic:Play() wait(.2) script.Parent.Rotation = 1 script.Open:Play() wait(.1) script.Parent.Visible = false wait(.1) script.Parent.Parent.Pet.Visible = true script.Parent.Parent.Pet.Text = "You got "..plr.GotPet.Value.." !" wait(2) script.Parent.Parent.Pet.Visible = false end end
Edit: If this is what you mean by where plr.gotpet is stored then its in my leaderstats:
game.StarterGui.ResetPlayerGuiOnSpawn = false local DataStoreService = game:GetService("DataStoreService") local playerData = DataStoreService:GetDataStore("PlayerData") game.Players.PlayerAdded:connect(function(Player) local leaderstats = Instance.new("Folder", Player) leaderstats.Name = "leaderstats" local val1 = Instance.new("StringValue",Player) val1.Name = 'GotPet' val1.Value = '' local val2 = Instance.new("StringValue",Player) val2.Name = 'OpenValue' val2.Value = '' local Gems = Instance.new("IntValue", leaderstats) Gems.Name = "Gems" Gems.Value = 0 local Rebirths = Instance.new("IntValue", leaderstats) Rebirths.Name = "Rebirths" Rebirths.Value = 0 local Coins = Instance.new("IntValue", leaderstats) Coins.Name = "Coins" Coins.Value = 0 local playerUserId = "Player_" .. Player.UserId --Gets player ID local Success, Result = pcall(function() return playerData:GetAsync(playerUserId) end) if Result then print("Data found!") Coins.Value = Result[1] -- // Since in the saving part, Coins are the one that is set as the first value of the table, we set Coins as [1] Rebirths.Value = Result[2] Gems.Value = Result[3] else print("DataStore working but No data found") warn(Result) end end) local function onPlayerExit(player) --Runs when players exit local success, Err = pcall(function() print("Data Saved successfully") local playerUserId = "Player_" .. player.UserId playerData:SetAsync(playerUserId, {player.leaderstats.Coins.Value, player.leaderstats.Rebirths.Value, player.leaderstats.Gems.Value}) -- Now set as a table instead of individually end) if not success then warn(Err) warn('Could not save data!') end end game.Players.PlayerRemoving:Connect(onPlayerExit)
and here is where the pet is chosen
local userInputService = game:GetService("UserInputService") local RS = game:GetService("ReplicatedStorage") local Eggs = require(RS:WaitForChild("Eggs")) local Data = Eggs[script.Name] local Cost = Data["Cost"] local Pets = Data["Pets"] local Buy = game.Workspace.Eggs.Common local Cost1 = Buy:WaitForChild("Cost") local CD = Buy.Buy.Select:WaitForChild("ImageButton") local CostGUI = Cost1:WaitForChild("Am") local CostText = CostGUI:WaitForChild("TextLabel") CostText.Text = Cost.." Coins" local TotalWeight = 0 for i,v in pairs(Pets) do TotalWeight = TotalWeight + v[1] end local function ChoosePet() local Chance = math.random(1,TotalWeight) local Counter = 0 for i,v in pairs(Pets) do Counter = Counter+v[1] if Chance <= Counter then return i end end end CD.Triggered:Connect(function(Player) local Stats = Player:WaitForChild("leaderstats") local Coins = Stats:WaitForChild("Coins") local open = Player:WaitForChild('OpenValue') local got = Player:WaitForChild('GotPet') if Coins.Value >= Cost then Coins.Value = Coins.Value - Cost open.Value = 'Open' got.Value = ChoosePet() local findpet = Player:WaitForChild('Pets') local sqq = findpet:FindFirstChild(got.Value) sqq.Value = 'owned' wait(5) open.Value = 'Close' got.Value = '' end end) -- // this code has an error on CD.Triggered i know. but im fixing that soon.
I dont have the images store anywhere currently as i dont know exactly where to store them.
You'll have to be more specific on where you get the images of pets. Are they saved somewhere in your game? Are they uploaded as decals? Where do you store the decal IDs?
In terms of your code though, there are many improvements you can make. The big one is using a loop instead of pasting (close to) the same code every time. Try something like this:
local plr = game.Players.LocalPlayer local open = plr:WaitForChild('OpenValue') while true do if open.Value == "Open" then script.Parent.Visible = true for i = 3, 6 do script.Parent.Rotation = i script.tic:Play() wait(0.2) script.Parent.Rotation = i * -1 script.tic:Play() wait(0.2) end script.Parent.Rotation = 1 script.Open:Play() wait(.1) script.Parent.Visible = false wait(.1) script.Parent.Parent.Pet.Visible = true script.Parent.Parent.Pet.Text = "You got "..plr.GotPet.Value.." !" -- You can add a line of code after this to set a pet image but you would need to share how GotPet is set. wait(2) script.Parent.Parent.Pet.Visible = false end wait(0.1) end
This will loop from 3 to 6, set the rotation to 3, then -3, then 4, then -4, then 5, and so on. Just like your code did, only this is a bit cleaner.
You'll have to provide some more info about the image data since you need to have them somewhere in order to load them (decal IDs).
You could just use ViewportFrames, and locate the camera infront of a position where you can place the pet?-
Not that hard, to be honest, you don't even need much code for it, unless you count
local a : ViewportFrame = ... a.Visible = false if (...) then a.Visible = true wait(...) a.Visible = false end