i do not know where it went wrong but the output says "Attempted to add a nil value" please help me. the script will touch a brick and a guy shows up and the brick tp the a random text.

local debounce = false

function OnTouched(objectThatHit)
    if objectThatHit.Parent:FindFirstChild('Humanoid') then --If there is a humanoid in the object's parent, then we know it's probably a character model.
        local player = game:GetService('Players'):GetPlayerFromCharacter(objectThatHit.Parent) --We should have the player by now. So we'll access it's PlayerGui.
        player.PlayerGui.ScreenGui1.Frame:TweenPosition(UDim2.new(.5,-250,0,0))
wait(0.001)

debounce = false
	function onTouch(part)
	local human = part.Parent:findFirstChild("Humanoid")
	if (human ~=nil) and debounce == false then
		debounce = true
	
	wait(1)
	game.Lighting.Part.Plart:Clone().Parent = game.Workspace
	wait(15)
	game.Workspace.Plart:Destroy()
	debounce = false


        wait(2)
        player.playerGui.ScreenGui1.Frame.TextLabel.Text = "C"
        wait(0.1)
player.playerGui.ScreenGui1.Frame.TextLabel.Text = "Ca"
        wait(0.1)
player.playerGui.ScreenGui1.Frame.TextLabel.Text = "Can"
        wait(0.1)
player.playerGui.ScreenGui1.Frame.TextLabel.Text = "Can i"
        wait(0.1)
player.playerGui.ScreenGui1.Frame.TextLabel.Text = "Can i h"
        wait(0.1)
player.playerGui.ScreenGui1.Frame.TextLabel.Text = "Can i he"
        wait(0.1)
player.playerGui.ScreenGui1.Frame.TextLabel.Text = "Can i hel"
        wait(0.1)
player.playerGui.ScreenGui1.Frame.TextLabel.Text = "Can i help"
        wait(0.1)
player.playerGui.ScreenGui1.Frame.TextLabel.Text = "Can i help y"
        wait(0.1)
player.playerGui.ScreenGui1.Frame.TextLabel.Text = "Can i help yo"
        wait(0.1)
player.playerGui.ScreenGui1.Frame.TextLabel.Text = "Can i help you"
        wait(0.1)
player.playerGui.ScreenGui1.Frame.TextLabel.Text = "Can i help you?"
        wait(0.1)
if objectThatHit.Parent:FindFirstChild('Humanoid') then --If there is a humanoid in the object's parent, then we know it's probably a character model.
        local player = game:GetService('Players'):GetPlayerFromCharacter(objectThatHit.Parent) --We should have the player by now. So we'll access it's PlayerGui.
        player.PlayerGui.ScreenGui1.Frame1:TweenPosition(UDim2.new(.5,-250,0,105))



    end
end
end
end
end




script.Parent.Touched:connect(OnTouched)
script.Parent.Touched:connect(onTouch)

1 comment

0

Completely un-related to your question, but you can shorten the text part a hell of a lot with a different method. Assign the string to a variable and loop through it, selecting what parts of your string you want shown using the string sub method (As shown here: https://scriptinghelpers.org/questions/24566/how-to-slice-a-string)