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

Why does this GUI script not work online?

The script I have made creates a GUI dialog on the touch of a brick. However it only works when played in the roblox studio, and not online, I am not sure why.. Is there anything wrong with the script?

function touch()
local screenGui = Instance.new("ScreenGui")
screenGui.Parent = game.Players.LocalPlayer.PlayerGui
 

local textLabel = Instance.new("TextLabel")
textLabel.Parent = screenGui
textLabel.Position = UDim2.new(0.55, 0, 0.7, 0)
textLabel.Size = UDim2.new(0, 600, 0, 200)
textLabel.BackgroundColor3 = BrickColor.DarkGray().Color
textLabel.TextWrapped = true
textLabel.FontSize = "Size28"
textLabel.Font = "SourceSansBold"
textLabel.Transparency = 0.4
textLabel.TextColor3 = BrickColor.White().Color
local finalText = [[	Hello there, ]]..game.Players.LocalPlayer.Name..[[ 
	How are you]]

for i = 0, #finalText do
    textLabel.Text = string.sub(finalText, 0, i)
    wait(.05)
end 
end
script.Parent.Touched:connect(touch)

1 answer

✓ Accepted answer

If this script is in the part then Change it to a normal script and utilize the parameter passed when the touch event occurs which is what hit it so you could do something like this

function touch(hit)
	if hit.Parent:IsA('Model') then
		local player = game.Players:FindFirstChild(hit.Parent.Name)
		
		if player then -- just good programming 
			-- now run the code you have using the new variable player when necessary
		end
	elseif hit.Parent.Parent:IsA('Model') then
		local player = game.Players:FindFirstChild(hit.Parent.Parent.Name)
		if player then
			-- same deal run the code here as well
		end
	end
end

script.Parent.Touched:connect(touch)

so what i did here was tested for what hit the part then checked to see if that part was part of a model which is how the character is set up in the workspace and if so then we looked in players to find the player then executed your code so it should work both in online mode and in an actual game

to answer the question of why it doesnt work online is because when u click run in studio it treats the client and server as the same thing whereas online they are not so that is something you should account for when scripting anything involving both the server and the client

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