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

Is it possible for other scripts to find a model created through a local script?

Hello, This is what I want to do: When a player touches a certain part let's call it part1, a model is created into the workspace that is only visible to them. Then when that same player touches another part (part2) they destroy that same model that was created following the touch event of part1. I've tried many different ways and all lead to the same result: The model is successfully created (or in this case cloned) into the workspace but after that when the time comes for part2 to delete the model nothing happens at all. I used the Touched event for both cases that activated a LocalScript in StarterCharacterScripts which would initiate the :Clone() / :Destroy() processes. I tried to use RemoteEvents as well but without any success. I am relatively new to Lua and coding as a whole.

2 comments

0

server and client are two separate categories so any localscript should be able to see local objects for only the player.

0

We got it all solved, thank you for your response.

1 answer

✓ Accepted answer

Well, since this is all Client-Sided we can have a LocalScript with the following:

local Player = game.Players.LocalPlayer

local RP = game:GetService("ReplicatedStorage")

local Part1 = workspace:FindFirstChild("Part1")
local Part2 = workspace:FindFirstChild("Part2")
local Model = RP:WaitForChild("Model"):Clone()

local db = false

Part1.Touched:Connect(function(touched)
	if game.Players:FindFirstChild(touched.Parent.Name) and touched.Parent.Name == Player.Name and db == false then
		db = true
		Model.Parent = workspace
	end
end)

Part2.Touched:Connect(function(touched)
	if game.Players:FindFirstChild(touched.Parent.Name) and touched.Parent.Name == Player.Name and db == true then
		db = false
		Model.Parent = nil
	end
end)

1 comment

0

This solved it, I just hadn't thought about putting everything in one single script. Thank you so much!

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