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?

function onTouch(hit)

script.Parent.Sound:Play()

script.Parent.Main.Transparency = 1

script.Parent.Main.CanCollide = false

script.Parent.Part.Transparency = 1

script.Parent.Part.CanCollide = false

script.Parent.Coil.Transparency = 1

script.Parent.Coil.CanCollide = false

script.Parent.Parent.Coil.Transparency = 0

script.Parent.Parent.Main.Transparency = 0

script.Parent.Parent.Part.Transparency = 0.5







if hit.Parent:FindFirstChild("Humanoid") ~= nil then



if game.Players:FindFirstChild(hit.Parent.Name) ~= nil then

local player = game.Players:FindFirstChild(hit.Parent.Name)



if player:FindFirstChild("PlayerGui"):FindFirstChild("ScreenGui") == nil then

sg = Instance.new("ScreenGui")

sg.Parent = player:FindFirstChild("PlayerGui")

end



if player.PlayerGui.ScreenGui:FindFirstChild("MessageBox") == nil then



local f = Instance.new("Frame")

f.Name = "MessageBox"

f.Position = UDim2.new(0.4, 0, 0.1, 0)

f.Size = UDim2.new(0.4, 0, 0, 50)

f.Style = "RobloxSquare"

f.Parent = player.PlayerGui:FindFirstChild("ScreenGui")



local m = Instance.new("TextLabel")

m.Position = UDim2.new(0.5, 0, 0.5, 0)

m.FontSize = "Size14"

m.TextColor3 = Color3.new(1,1,1)



script.Parent.Main:Destroy()

------------------------------------------



m.Text = "You found a fuse... the night goes on."

wait(9)





------------------------------------------



f:Destroy()



end

end

end

end



script.Parent.Main.Touched:connect(onTouch)

2

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