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

Script just ignores the frame in the screengui why?

Asked by
DevingDev 346 Moderation Voter
7 years ago

So, I am making a vote for a map gui but i got one problem the "MapVoting" script can't find the frame in the gui it just ignore the frame that it is sepose to find. And i dont know why this script cant find that frame so i need some help. Someone who knows why it just ignores the frame in the screengui?

Script:

local votedFor = 0
local info = require(game.ReplicatedStorage.MapInformation)

game.ReplicatedStorage.ServerRequest.ShowMapOptions.OnClientEvent:connect(function(map1,map2,map3)
    votedFor = 0

    local map1Info = info.GetDetails(map1)
    local map2Info = info.GetDetails(map2)
    local map3Info = info.GetDetails(map3)

    -- Map1
    script.Parent.Frame.Map1.MapName.Text = map1Info[2]
    script.Parent.Frame.Map1.Image = "rbxassetid://"..map1Info[3]
    -- Map2
    script.Parent.Frame.Map2.MapName.Text = map2Info[2]
    script.Parent.Frame.Map2.Image = "rbxassetid://"..map2Info[3]
    -- Map3
    script.Parent.Frame.Map3.MapName.Text = map3Info[2]
    script.Parent.Frame.Map3.Image = "rbxassetid://"..map3Info[3]

    script.Parent.Frame.Visible = true
    script.Parent.Frame:TweenPosition(UDim2.new(0.5,-250,0.5,-100),"Out","Quad",1)

    wait(10)
    script.Parent.Frame:TweenPosition(UDim2.new(0.5,-250,1.5,-100),"Out","Quad",1)  
    wait(2)
    script.Parent.Frame.Visible = false
end)

game.ReplicatedStorage.ServerRequest.ShowMapScores.OnClientEvent:connect(function(map1,map2,map3)
    script.Parent.Frame.Map1.Votes.Text = map1
    script.Parent.Frame.Map2.Votes.Text = map2
    script.Parent.Frame.Map3.Votes.Text = map3
end)

script.Parent.Frame.Map1.MouseButton1Click:connect(function()
    if votedFor == 0 then
        votedFor = 1
        game.ReplicatedStorage.ClientRequest.VoteForMap:FireServer(true,votedFor)
    elseif votedFor == 1 then
        game.ReplicatedStorage.ClientRequest.VoteForMap:FireServer(false,votedFor)
        votedFor = 0
    else
        game.ReplicatedStorage.ClientRequest.VoteForMap:FireServer(false,votedFor)
        votedFor = 1
        game.ReplicatedStorage.ClientRequest.VoteForMap:FireServer(true,votedFor)
    end
end)

script.Parent.Frame.Map2.MouseButton1Click:connect(function()
    if votedFor == 0 then
        votedFor = 2
        game.ReplicatedStorage.ClientRequest.VoteForMap:FireServer(true,votedFor)
    elseif votedFor == 2 then
        game.ReplicatedStorage.ClientRequest.VoteForMap:FireServer(false,votedFor)
        votedFor = 0
    else
        game.ReplicatedStorage.ClientRequest.VoteForMap:FireServer(false,votedFor)
        votedFor = 2
        game.ReplicatedStorage.ClientRequest.VoteForMap:FireServer(true,votedFor)
    end
end)

script.Parent.Frame.Map3.MouseButton1Click:connect(function()
    if votedFor == 0 then
        votedFor = 3
        game.ReplicatedStorage.ClientRequest.VoteForMap:FireServer(true,votedFor)
    elseif votedFor == 3 then
        game.ReplicatedStorage.ClientRequest.VoteForMap:FireServer(false,votedFor)
        votedFor = 0
    else
        game.ReplicatedStorage.ClientRequest.VoteForMap:FireServer(false,votedFor)
        votedFor = 3
        game.ReplicatedStorage.ClientRequest.VoteForMap:FireServer(true,votedFor)
    end
end)

Error:

17:24:50.273 - Frame is not a valid member of ScreenGui
17:24:50.273 - Stack Begin
17:24:50.274 - Script 'Players.Player2.PlayerGui.VoteGui.MapVoting', Line 36

1 answer

Log in to vote
0
Answered by
RubenKan 3615 Moderation Voter Administrator Community Moderator
7 years ago
Edited 7 years ago

This error is mostly occuring due to the script being loaded before the gui is loaded, or the object actualy doesn't exist.

This is easily fixable by adding this line in your script:

script.Parent:WaitForChild("Frame")

This will tell the script to yield(wait) until it finds an object with the name "Frame"

0
Thanks, It got rid of the error but the fram didint show up DevingDev 346 — 7y
0
Is the Frame called Frame? if not script.Parent:WaitForChild("PutFrameNameHere") Pejorem 164 — 7y
0
Yes the frame is called frame otherwise i would say that DevingDev 346 — 7y
Ad

Answer this question