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

Attempt to call UserData error?

So I'm using this script in a SurfaceGui which is attached to a part in the game so all players can use it locally, note my game is filtering enabled.

local jobName = "Cafe"
local announceText = "Urban Life Jobs | You now work at "..jobName.."!"
local plr = game.Players.LocalPlayer
local plrGui = plr:FindFirstChild("PlayerGui")
local announce = plrGui.mainGui.Border
print("Hola")

script.Parent.MouseButton1Down:connect(function()
	local announceMsg = game.Players.LocalPlayer.PlayerGui:FindFirstChild("announceBar")
	if announceMsg == true then
		local textBar = Instance.new("Frame", announce)	
		textBar.Name = "textBar"
		textBar.Size = UDim2.new(1, 0, 0, 20)
		textBar.Position = UDim2.new(0, 0, -1, 0)
		textBar.BackgroundTransparency = 0
		textBar.BorderSizePixel = 0
		local bar = Instance.new("TextLabel", textBar)
		bar.BackgroundTransparency = 0
		bar.Text = announceText
		bar.Position = UDim2.new(0, 0, -1, 0)
		bar.Size = UDim2.new(1, 0, 0, 20)
		bar.TextColor3 = Color3.fromRGB(255, 0, 0)
		bar.Font = "SouceSansLight"
		bar.FontSize = "Size18"
		bar.Name = "announceBar"
		bar.TextScaled = true
		bar.TextWrapped = true
		wait(1)
		plrGui.mainGui.Border.textBar:TweenPosition(UDim2.new(0, 0, 0, 0) 'Out', 'Linear', 1, false)
		announceMsg.Position:TweenPosition(UDim2.new(announceMsg.Position + UDim2.new(0, 0, 0.05, 0)), 'Out', 'Linear', 1, false)
	else	
		local textBar = Instance.new("Frame", announce)
		textBar.Name = "textBar"
		textBar.Size = UDim2.new(1, 0, 0, 20)
		textBar.BackgroundTransparency = 0
		textBar.BorderSizePixel = 0	
		local bar = Instance.new("TextLabel", textBar)
		bar.BackgroundTransparency = 0
		bar.Text = announceText
		bar.Position = UDim2.new(0, 0, -1, 0)
		bar.Size = UDim2.new(1, 0, 0, 20)
		bar.TextColor3 = Color3.fromRGB(255, 0, 0)
		bar.Font = Enum.Font.SourceSansLight
		bar.FontSize = Enum.FontSize.Size18
		bar.Name = "announceBar"
		bar.TextScaled = true
		bar.TextWrapped = true
		wait(1)
		plrGui.mainGui.Border.textBar:TweenPosition(UDim2.new(0, 0, 0, 0) 'Out', 'Linear', 1, false)
	end
end)

The error I'm receiving is:

Players.Player1.PlayerGui.JobSelector.ScrollingFrame.B-cafeJob.LocalScript:53: attempt to call a userdata value

EDIT: I just fixed the script, I decided to use a remote event to transfer the values instead

2 comments

0

Which line is line 53?

0

It's okay I fixed it :) I just used a remote event

1 answer

local JobName = "Cafe"
local AnnounceText = "Urban Life Jobs | You now work at " .. JobName .. "!"
local LocalPlayer = game.Players.LocalPlayer
local PlayerGui = LocalPlayer:FindFirstChild("PlayerGui")
local Announce = PlayerGui.mainGui.Border

script.Parent.MouseButton1Down:Connect(function()
	local AnnounceMsg = PlayerGui:FindFirstChild("announceBar")
	
	if AnnounceMsg then
		local TextBar = Instance.new("Frame", Announce) 
		TextBar.Name = "textBar"
		TextBar.Size = UDim2.new(1, 0, 0, 20)
		TextBar.Position = UDim2.new(0, 0, -1, 0)
		TextBar.BackgroundTransparency = 0
		TextBar.BorderSizePixel = 0
		
		local Bar = Instance.new("TextLabel", TextBar)
		Bar.BackgroundTransparency = 0
		Bar.Text = AnnounceText
		Bar.Position = UDim2.new(0, 0, -1, 0)
		Bar.Size = UDim2.new(1, 0, 0, 20)
		Bar.TextColor3 = Color3.fromRGB(255, 0, 0)
		Bar.Font = Enum.Font.SourceSansLight
		Bar.FontSize = Enum.FontSize.Size18
		Bar.Name = "announceBar"
		Bar.TextScaled = true
		Bar.TextWrapped = true
		
		wait(1)
		
		TextBar:TweenPosition(UDim2.new(0, 0, 0, 0) 'Out', 'Linear', 1, false)
		AnnounceMsg.Position:TweenPosition(UDim2.new(AnnounceMsg.Position + UDim2.new(0, 0, 0.05, 0)), 'Out', 'Linear', 1, false)
	else
		local TextBar = Instance.new("Frame", Announce)
		TextBar.Name = "textBar"
		TextBar.Size = UDim2.new(1, 0, 0, 20)
		TextBar.BackgroundTransparency = 0
		TextBar.BorderSizePixel = 0
		
		local Bar = Instance.new("TextLabel", TextBar)
		Bar.BackgroundTransparency = 0
		Bar.Text = AnnounceText
		Bar.Position = UDim2.new(0, 0, -1, 0)
		Bar.Size = UDim2.new(1, 0, 0, 20)
		Bar.TextColor3 = Color3.fromRGB(255, 0, 0)
		Bar.Font = Enum.Font.SourceSansLight
		Bar.FontSize = Enum.FontSize.Size18
		Bar.Name = "announceBar"
		Bar.TextScaled = true
		Bar.TextWrapped = true
		
		wait(1)

		TextBar:TweenPosition(UDim2.new(0, 0, 0, 0) 'Out', 'Linear', 1, false)
	end
end)

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