Improvements
Use WaitForChild() to make sure an instance exists before using it
Use GetService() for the Players Service
Use workspace instead of game.Workspace
Use SetPrimaryPartCFrame to move the player's Character model instead of moving the PrimaryPart only
Use Activated for GuiButtons in order for it to work on all devices and not just computers
Explanation
In the below you can see that I first make a local variable for the module which "requires" the module (Line 3)
Later, when determining the button's Text, I use a function ive defined in the module and send in the button's name as a parameter
In the module script, I make a table dictating the index (which matches my button's name ("Button1") and give this position in the table the value ["Section 7"]
When the function is called, I return this value, which is returned with the module which had previously been "required"
Notice, module scripts only run when you use "require" so it will not run when the server is created like LocalScripts or Server Scripts
Local Script
local player = game:GetService("Players").LocalPlayer
local target = workspace:WaitForChild("Misc"):WaitForChild("TPfloors"):WaitForChild("TPsec7")
local module = require(game:GetService("ReplicatedStorage"):WaitForChild("StringList"))
local button = script.Parent
local db = true
local delay = 2
button.Activated:Connect(function()
if db == true then
db = false
player.Character:SetPrimaryPartCFrame(target.CFrame * CFrame.new(0, 8, 0))
for i = delay, 1, -1 do
button.Text = i
wait(1)
end
button.Text = module.StringReturn(button.Name)
db = true
end
end)
Module Script
local module = {}
function module.StringReturn(button)
local stbl = {["Button1"] = "Section 7"}
return(stbl[button])
end
return(module)
EDIT
Running the same function is similar to changing the button's text, except we'll keep it in the module (it will act like a local function)
Local Script
local player = game:GetService("Players").LocalPlayer
local module = require(game:GetService("ReplicatedStorage"):WaitForChild("StringList"))
local button = script.Parent
local db = true
button.Activated:Connect(function()
if db == true then
db = false
db = module.StringReturn(button, player)
end
end)
Module Script
local module = {}
local target = workspace:WaitForChild("Misc"):WaitForChild("TPfloors"):WaitForChild("TPsec7")
local delay = 2
function module.StringReturn(button, player)
local stbl = {["Button1"] = "Section 7"}
player.Character:SetPrimaryPartCFrame(target.CFrame * CFrame.new(0, 8, 0))
for i = delay, 1, -1 do
button.Text = i
wait(1)
end
button.Text = stbl[button.Name]
return(true)
end
return(module)
4 comments
What part of this code did you want to put into a module script? the text that is returned? (i.e. "Section 7") if so, itd help to clarify a bit as to how you want the module to return the text (based on a keyword, the button's name, etc)
So basically, I need it so I can just use require() in a couple different local scripts if that makes any sense, but I also need it so where the text says the right thing for the right button. Hope this helps some?
i just edited my answer to explain your needs
Responding to your comment, i've adjust the scripts in my response, which should better suit what you are trying to accomplish