Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

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)

2 comments

0

Didin't work

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.