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

Fix this for me to make a gui pop up when touched?

Asked by
mnaj22 44
9 years ago
Name = script.Parent.Value.Value
function onTouched(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        local character = hit.Parent:FindFirstChild("Humanoid")
        local plr = game.Players:GetPlayerFromCharacter(character)
            if plr then
                local value = math.random(1, 5)
                plr.PlayerGui.Number.TextLabel.Text = "Your number is  " .. Name
                plr.PlayerGui.Number.TextLabel.Visible = true
                wait(6)
                plr.PlayerGui.Number.TextLabel.Visible = false
        end
    end
end
script.Parent.Touched:connect(onTouched)

1 answer

Log in to vote
0
Answered by 9 years ago

The first thing you did wrong was making the character variable the humanoid. 2nd you named value, which could be ommited (taken out) since it is n't used. 3rd I suggest you add a wait in to make sure you don't keep getting numbers. Here is what I came up with.

Name = script.Parent.Value
db=false
function onTouched(hit)
    if db==false then
        db=true
        if hit.Parent:FindFirstChild("Humanoid") then
            local character = hit.Parent
            local plr = character.Parent
            if plr then
                Name.Value = math.random(1, 5)
                plr.PlayerGui.Number.TextLabel.Text = "Your number is  " .. Name
                plr.PlayerGui.Number.TextLabel.Visible = true
                wait(6)
                plr.PlayerGui.Number.TextLabel.Visible = false
            end
        end
        db=false
    end
end
script.Parent.Touched:connect(onTouched)
0
Didin't work mnaj22 44 — 9y
0
The problem here is that XtremeSpy failed to correctly define plr. Defining plr as character.Parent is incorrect as it is equivalent to Workspace, which is not what we want. Use the GetPlayerFromCharacter function to define plr. plr = game.Players:GetPlayerFromCharacter(character) IcyArticunoX 355 — 9y
Ad

Answer this question