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

Why wont my feature that works in Studio work in game?

I have a script that clones a part into the CurrentCamera of the player, then when the push a button it destroys the part. I have it like this so it only deletes the part for 1 person, not the whole server. The script looks like this and is inside of a localscript in the StarterGui tab

game.ReplicatedStorage:WaitForChild("Door"):Clone().Parent = workspace.CurrentCamera
local button = workspace.Rooms.VeryEasy.Room2.GreenButton1


-- Create a ClickDetector
local ClickDetector = Instance.new("ClickDetector")
ClickDetector.Parent = button
ClickDetector.MaxActivationDistance = 10
 
-- Open the button on left mouse click
ClickDetector.MouseClick:Connect(function()
	print("work3")
	workspace.CurrentCamera.Door:Destroy()
end)

It creates and destroys the part in Roblox Studio, but it doesn't do the same in the actual game. If anyone needs more info on what I want it to do, its on the second green stage in this game https://www.roblox.com/games/4989653371/Tower-Escape-Pre-Alpha-UPDATE?refPageId=fb5fb20e-4f2a-4cbf-9511-07f4a7127df0 (it takes literally under 30 seconds to get there)

1 answer

✓ Accepted answer
script.Parent.ClickDetector.MouseClick:Connect(function(player)
	script.Parent.RemoteEvent:FireClient(player)
end)

Include this in the part with the clickdetector. When the player clicks it, it will fire the event for the player who clicked it. This is also a normal script. Make sure you also include a remoteevent in the part.

local Event = workspace.Rooms.VeryEasy.Room2.GreenButton1.RemoteEvent

Event.OnClientEvent:Connect(function(player)
	if workspace.Rooms.VeryEasy.Room2:FindFirstChild("Door") then
	workspace.Rooms.VeryEasy.Room2.Door:Destroy()
end
end)

This script will go into the StarterPlayerScripts. This will be a local script as well. This tells the Event what needs to happen when it is fired. This will delete only the part on the client's side.

Hope this helped!

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