Ad
Log in to vote
0

How do I make a gui inserted when a player walks over an object?

Asked by
manith513 101
3 years ago

My position settings say the gui should not be on the screen and I want it like that but whenever I play the game the gui doesn't show up as a new text button in the starter gui Help.~~~~~~~~~~~~~~~~~ game.Workspace.Hill1.NamePlate.Touched:Connect(function(player) if player.claim == false then if game.Workspace.Hill1.Claimed.Value == false then local claim = Instance.new("TextButton", game.StarterGui.ScreenGui) claim.Position = UDim2.new(0.408, 0,0, -100)

    end



end

end)

~~~~~~~~~~~~~~~~~

2 answers

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

You have a lot of problems with your script but I'm just gonna fix the main ones for you.

workspace.Hill1.NamePlate.Touched:Connect(function(hit)
    local player = game:GetService('Players'):GetPlayerFromCharacter(hit.Parent)
    if player ~= nil and player.claim.Value == false then
        if game.Workspace.Hill1.Claimed.Value == false then
            local claim = Instance.new("TextButton", player.PlayerGui.ScreenGui)
            claim.Position = UDim2.new(0.408, 0,0, -100) 
        end
    end
end)

First off .Touched passes whatever object touched it as an argument, not the player, so I just fixed that to actually get the player. You also were doing parenting the TextButton to StarterGui instead of the actual PlayerGui.

Hope this fixed your problem!

0
Hi umm It doesn't seem to be working whenever I touch the block... I haven't editied anything before this response. I also tested you script with a local script and a normal script but none seem to be working also, Do you mind explaining a bit further about the GetPlayerFromCharacter and how i works I am fairly new to lua so I don't know much manith513 101 — 3y
0
Hi also one more thing, do you mind viewing my other question arrow to destination please? a million thx manith513 101 — 3y
0
Nvr mind it works looking in the wrong place :P thx. Please consider looking at the other question please thx. manith513 101 — 3y
Ad
Log in to vote
0
Answered by
manith513 101
3 years ago
Edited 3 years ago

Sorry Here is how the code block should look like

game.Workspace.Hill1.NamePlate.Touched:Connect(function(player)
    if player.claim == false then
        if game.Workspace.Hill1.Claimed.Value == false then
            local claim = Instance.new("TextButton", game.StarterGui.ScreenGui)
            claim.Position = UDim2.new(0.408, 0,0, -100) 

        end



    end

end)

that block of code was in a local script Here is the script to insert the boolean value into the player (which works) it is a normal script

Answer this question