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

How do I change a script so that it works online?

I'm trying to create a script where you touch a door and it will check whether or not you own a tycoon and either make you the owner of the new tycoon if you don't or do nothing if you already own a tycoon.

If anyone can alter this script or give me some sort of help as to how I can accomplish this to work while being server-sided then I'd greatly appreciate it as I am completely at a loss as to where I can even begin.

wait(2)
local tycoon = game.Workspace.Tycoon1
local owner = tycoon.Main.Owner
local debounce = false

script.Parent.Touched:connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player ~= nil and debounce == false then
local alert = player.PlayerGui.TycoonGui.Alert
debounce = true
print'Check for Ownership'
if player.Tycoon.Value == 1 then
alert.Text = "You already own a tycoon!"
alert.Type.Value = "Alert"
alert.On.Value = true
return end
owner.Value = player.Name
player.Tycoon.Value = 1
alert.Text = "You now own this tycoon, " ..player.Name.. "!"
alert.Type.Value = "Message"
alert.On.Value = true
for i = 0.4, 1, 0.01 do
wait()
script.Parent.Transparency = i
end
script.Parent.Parent:Destroy()
end
wait(2)
debounce = false
end)

4 comments

0

Use :Connect instead of :connect, but this won't solve the problem.

0

Did you get anything from the output?

0

Please indent your code so it doesn't give me eye spasms :)

0

make sure hit is actually a player as well

1 answer

✓ Accepted answer

You should use :Connect() instead of using :connect() as it's deprecated. I changed return end in your script with elseif because I think that theres the problem. Please don't blame me if I am wrong cuz I am not very familiar with "return". I also used TweenService instead of loop.

wait(2)
local tycoon = game.Workspace.Tycoon1
local owner = tycoon.Main.Owner
local debounce = false -- Prevents a ton of hits

local part = script.Parent

local TweenService = game:GetService("TweenService")

local Goal = {}
Goal.Transparency = 1

local tweenInfo = TweenInfo.new(2) -- Time it takes to fade out a part.

local Tween = TweenService:Create(part, tweenInfo, Goal)
 
script.Parent.Touched:connect(function(hit)

local player = game.Players:GetPlayerFromCharacter(hit.Parent) -- Gets player from character

if player ~= nil and debounce == false then

local alert = player.PlayerGui:WaitForChild("TycoonGui").Alert

debounce = true

print("Check for Ownership")

if player.Tycoon.Value == 1 then

alert.Text = "You already own a tycoon!"
alert.Type.Value = "Alert"
alert.On.Value = true

elseif player.Tycoon.Value == 0 then

owner.Value = player.Name
player.Tycoon.Value = 1
alert.Text = "You now own this tycoon, " ..player.Name.."!"
alert.Type.Value = "Message"
alert.On.Value = true

Tween:Play()

wait(2)

script.Parent.Parent:Destroy()
end
wait(2)
debounce = false

end)

Not quite sure that this will work, BTW typed from Phone. SORRY if there are any errors or mistakes I created.

4 comments

0

It works perfectly during solo testing, but once again in online testing it still won't detect a player touching it.

0

attempt to index a nil value

0

Did you fixed it or?

0

Fixed the detection issue, just figuring out the GUI part. Thank you for the help!

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