Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Script works in Roblox Studios, but not in the published game?

Asked by 5 years ago

SO what this script does is that you touch a part of a Model, it destroys the part with the touch function after making it invisible, and then makes the model the model is in visible, but it only works in studios. Any help?

001function onTouch(hit)
002 
003script.Parent.Sound:Play()
004 
005script.Parent.Main.Transparency = 1
006 
007script.Parent.Main.CanCollide = false
008 
009script.Parent.Part.Transparency = 1
010 
011script.Parent.Part.CanCollide = false
012 
013script.Parent.Coil.Transparency = 1
014 
015script.Parent.Coil.CanCollide = false
016 
017script.Parent.Parent.Coil.Transparency = 0
018 
019script.Parent.Parent.Main.Transparency = 0
020 
021script.Parent.Parent.Part.Transparency = 0.5
022 
023 
024 
025 
026 
027 
028 
029if hit.Parent:FindFirstChild("Humanoid") ~= nil then
030 
031 
032 
033if game.Players:FindFirstChild(hit.Parent.Name) ~= nil then
034 
035local player = game.Players:FindFirstChild(hit.Parent.Name)
036 
037 
038 
039if player:FindFirstChild("PlayerGui"):FindFirstChild("ScreenGui") == nil then
040 
041sg = Instance.new("ScreenGui")
042 
043sg.Parent = player:FindFirstChild("PlayerGui")
044 
045end
046 
047 
048 
049if player.PlayerGui.ScreenGui:FindFirstChild("MessageBox") == nil then
050 
051 
052 
053local f = Instance.new("Frame")
054 
055f.Name = "MessageBox"
056 
057f.Position = UDim2.new(0.4, 0, 0.1, 0)
058 
059f.Size = UDim2.new(0.4, 0, 0, 50)
060 
061f.Style = "RobloxSquare"
062 
063f.Parent = player.PlayerGui:FindFirstChild("ScreenGui")
064 
065 
066 
067local m = Instance.new("TextLabel")
068 
069m.Position = UDim2.new(0.5, 0, 0.5, 0)
070 
071m.FontSize = "Size14"
072 
073m.TextColor3 = Color3.new(1,1,1)
074 
075 
076 
077script.Parent.Main:Destroy()
078 
079------------------------------------------
080 
081 
082 
083m.Text = "You found a fuse... the night goes on."
084 
085wait(9)
086 
087 
088 
089 
090 
091------------------------------------------
092 
093 
094 
095f:Destroy()
096 
097 
098 
099end
100 
101end
102 
103end
104 
105end
106 
107 
108 
109script.Parent.Main.Touched:connect(onTouch)
110 
1112

2 answers

Log in to vote
1
Answered by 5 years ago

Use RemoteEvents.

Client Side can't edit Server Side (unless you want one player to see one thing and no one else).

Server Side can't edit Client Side.

Ad
Log in to vote
1
Answered by 5 years ago

UnderStanding

To do this u all have to use Filtering Enabled. This will basically send an event to the server which will be seen by all the client.

–Scripting it–

To do this you obviously need a RemoteEvent. I suggest putting it in ReplicatedStorage because it can be seen by the client and the server.

Do do such u need to create it:
local Remote = Instance.new(“RemoteEvent”)
Remote.Parent = game.ReplicatedStorage

— ServerScript–

Once you’ve done that u need to add the Touched event along with the FireServer Event that will fire the event to the server:

script.Parent.Main.Touched:Connect(function()
–Add in your Remote Script–
local Remote = Instance.new(“RemoteEvent”)
Remote.Parent = game.ReplicatedStorage
–Finally fire it to server
Remote:FireServer(hit)–Make sure to put events that you need etc:hit
end)

–LocalScript–

Put the local script in starter gui because that a place where it works.
You then have the what I call receive the Remote which should look like:

game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function()

end)

Once you’ve done this you need to add your script inside that event

game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(Player)
–Make sure to add a Player argument
–Add your whole script u posted here
–Remember if u have any variables put in in the brackets
end)

If this Explains and helps you with your script please put a check mark thingy.
For better explanation follow this video:[(https://www.youtube.com/watch?v=vpPVNDXvfy8&list=PL9XdvFXu9ApD4Kt_StK1AgApdK9u6uRM-&index=4)]

Answer this question