Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Text from textlabel not changing when it is suppose to? (no errors)

Asked by 1 year ago

Hello. I hope you are having a good day! Like I said in the title the text in a text label is not changing (P.S. I watched Alvinblox's egg hatching system tutorial) here is the script

local camera = workspace.Camera
local studio = workspace.Studio
local template = script.Parent.Pets.ScrollingFrame.Template
local scrollingFrame = script.Parent.Pets.ScrollingFrame
local buttonConnection = {}
local sparkles = studio["Egg Mesh"].Sparkles

local function setTemplateEquipped()
    for i,v in pairs(scrollingFrame:GetChildren()) do
        if v:FindFirstChild("Equipped") then
            v.Equipped.Text = "Unequipped"
            v.Equipped.TextColor3 = Color3.fromRGB(255,0,0)
        end
    end
    template.Equiped.Text = "Equipped"
    template.Equiped.TextColor3 = Color3.fromRGB(0,255,0)
end

local function addToFrame(pet)
    local newTemplate = template:Clone()
    newTemplate.Name = pet.Name
    newTemplate.petName.Text = pet.Name
    newTemplate.Parent = scrollingFrame
    newTemplate.Visible = true
    local camera = Instance.new("Camera")
    local newPet = pet:Clone()
    newPet.Parent = newTemplate.ViewportFrame
    camera.CFrame = CFrame.new(newPet.PrimaryPart.Position + (newPet.PrimaryPart.CFrame.LookVector * 3), newPet.PrimaryPart.Position)
    camera.Parent = newTemplate.ViewportFrame
    newTemplate.ViewportFrame.CurrentCamera = camera
    buttonConnection[#buttonConnection+1] = newTemplate.MouseButton1Click:Connect(function()
        if newTemplate.Equiped.Text == "Equipped" then
            game.ReplicatedStorage.unequipPet:FireServer(pet.Name)
            newTemplate.Equiped.Text = "Unequipped"
            newTemplate.Equiped.TextColor3 = Color3.fromRGB(255,0,0)
        else
            game.ReplicatedStorage.equipPet:FireServer(pet.Name)
            setTemplateEquipped(newTemplate)
        end
    end)
end

game.ReplicatedStorage.HatchEgg.OnClientEvent:Connect(function (pet)
    addToFrame(pet)
    camera.CameraType = Enum.CameraType.Scriptable
    camera.CFrame = studio.CameraPart.CFrame
    wait(1.5)
    for i = 1,50,1 do
        studio["Egg Mesh"].Size = studio["Egg Mesh"].Size + Vector3.new(0.1,0.1,0.1)
        wait(0.01)
    end
    local explosion = Instance.new("Explosion")
    explosion.BlastRadius = 10
    explosion.BlastPressure = 0
    explosion.Position = studio["Egg Mesh"].Position
    explosion.ExplosionType = Enum.ExplosionType.NoCraters
    explosion.DestroyJointRadiusPercent = 0
    explosion.Parent = studio["Egg Mesh"]
    studio["Egg Mesh"].Transparency = 1
    local petClone = pet:Clone()
    for i,v in pairs(petClone:GetChildren()) do
        if v:IsA("ParticleEmitter") then
            v.Enabled = true
        end
    end 
    sparkles.Enabled = false
    petClone:SetPrimaryPartCFrame(CFrame.new(studio["Egg Mesh"].Position, studio.CameraPart.Position))
    petClone.Parent = studio
    petClone.PrimaryPart.Position = Vector3.new(-14.382, -8.112, -605.565)
    petClone.PrimaryPart.Anchored = true
    local tweenInfo = TweenInfo.new(
        2,
        Enum.EasingStyle.Bounce,
        Enum.EasingDirection.Out,
        0,
        false,
        0
    )
    local TweenService = game:GetService("TweenService")
    local targetVector = petClone.PrimaryPart.Position + (petClone.PrimaryPart.CFrame.lookVector * 5) + Vector3.new(0,0.75,0)
    local lookVector = petClone.PrimaryPart.Position
    local targetCframe = CFrame.new(targetVector, lookVector)
    local propsToTween = { CFrame = targetCframe }
    local tween  = TweenService:Create(camera, tweenInfo, propsToTween)
    tween:Play()
    wait(5)
    for i,v in pairs(petClone:GetChildren()) do
        if v:IsA("ParticleEmitter") then
            v.Enabled = false
        end
    end 
    camera.CameraType = Enum.CameraType.Custom
    studio["Egg Mesh"].Transparency = 0
    studio["Egg Mesh"].Size = Vector3.new(4.732, 6, 4.732)
    petClone:Destroy()
    sparkles.Enabled = true
end)

Buybasicegg

local cost = 50
local petMoudle = require(game.ServerScriptService.BasicEggModule)
local prompt = workspace["Egg Holder"].Part.ProximityPrompt


prompt.Triggered:Connect(function (player)
    if player.leaderstats.Cash.Value >= cost then
        player.leaderstats.Cash.Value = player.leaderstats.Cash.Value - cost
        local pet = petMoudle.chooseRandomPet()
        local petval = Instance.new("StringValue")
        petval.Name = pet.Name
        petval.Parent = player.PetInventory
        print(pet.Name.." selected")
        game.ReplicatedStorage.HatchEgg:FireClient(player, pet)
    end
end)

petfollowplayer

local function equipPet(player, pet, petName)
    print(player)
    local character = player.Character
    if pet ~= nil and character ~= nil then
        if character:FindFirstChild(player.Name.."s' pet") then
            character(player.Name.."s' pet"):Destroy()
        end
        if character.HumanoidRootPart:FindFirstChild("attachmentCharacter") then
            character.HumanoidRootPart:FindFirstChild("attachmentCharacter"):Destroy()
        end
        pet.Name = player.Name.."'s pet"
        pet:SetPrimaryPartCFrame(character.HumanoidRootPart.CFrame)
        local modelSize = pet.PrimaryPart.Size
        local attachmentCharacter = Instance.new("Attachment")
        attachmentCharacter.Visible = false
        attachmentCharacter.Parent = character.HumanoidRootPart
        attachmentCharacter.Position = Vector3.new(-1,0,1) + modelSize
        attachmentCharacter.Name = "attachmentCharacter"
        local attachmentPet = Instance.new("Attachment")
        attachmentPet.Parent = pet.PrimaryPart
        local alignPosition = Instance.new("AlignPosition")
        alignPosition.MaxForce = 25000
        alignPosition.Attachment0 = attachmentPet
        alignPosition.Attachment1 = attachmentCharacter
        alignPosition.Responsiveness = 25
        alignPosition.Parent = pet
        local alignOrientation = Instance.new("AlignOrientation")
        alignOrientation.MaxTorque = 25000
        alignOrientation.Attachment0= attachmentPet
        alignOrientation.Attachment1= attachmentCharacter
        alignOrientation.Responsiveness = 25
        alignOrientation.Parent = pet

        pet.Parent = character
    end
end

game.Players.PlayerAdded:Connect(function(player)
    local equipedPet = Instance.new("StringValue")
    equipedPet.Name = "EquipedPet"
    equipedPet.Parent = player
    equipedPet.Value = ""
    player.CharacterAdded:Connect(function(char)
        if game.ReplicatedStorage:WaitForChild("HatchablePets"):FindFirstChild(equipedPet.Value) then
            local clone =game.ReplicatedStorage:WaitForChild("HatchablePets"):FindFirstChild(equipedPet.Value):Clone()
            equipPet(player,clone)
        end
    end)
    equipedPet.Changed:Connect(function ()
        if equipedPet.Value ~= nil then
            if game.ReplicatedStorage:WaitForChild("HatchablePets"):FindFirstChild(equipedPet.Value) then
                equipPet(player, game.ReplicatedStorage:WaitForChild("HatchablePets"):FindFirstChild(equipedPet.Value):Clone())

            end
        end
    end)
end)
game.ReplicatedStorage.equipPet.OnServerEvent:Connect(function(player,petName)
    local pet = game.ReplicatedStorage.HatchablePets:FindFirstChild(petName)
    if pet and player.PetInventory:FindFirstChild(petName) then
        player.EquipedPet.Value = petName
    end
end)
game.ReplicatedStorage.unequipPet.OnServerEvent:Connect(function(player)
    player.EquippedPet.Value = ""
    if player.Character:FindFirstChild(player.Name.."'s name") then
        player.Character[player.Name.."'s pet"]:Destroy()
    end
    if player.Character.HumanoidRootPart:FindFirstChild("attachmentCharacter") then
        player.Character.HumanoidRootPart:FindFirstChild("attachmentCharacter"):Destroy()
    end
end)


Help will be very appreciated^^

0
Can you show the entire explorer? Maybe you misspelled something in the script. T3_MasterGamer 2189 — 1y
0
Did you try changing workspace to game.Workspace? Hi_People1133 218 — 1y

1 answer

Log in to vote
0
Answered by 1 year ago

I've had this problem before. The fix is a little complicated. You need to use a server script to create or change a value, whether it's a player's username or their egg.

SERVER SCRIPT EXAMPLE:

local petName = "Alvin_Blox Plushie"

local stringVal = game.ReplicatedStorage:WaitForChild("StringVal")

stringVal.Value = petName

PUT THIS INSIDE OF THE TEXTLABEL IN THE GUI:

while true do
    local text = game.ReplicatedStorage:WaitForChild("StringVal")

    script.Parent.Text = tostring(text)

    wait()
end

This should make it Automatically update.

[MARK ME "ANSWERED" IF I WAS RIGHT!!! IT HELPS ME GAIN REPUTATION!!!!!!!!!!!!]

Ad

Answer this question