-
What do you want to achieve? Keep it simple and clear!
For the model script to update and place the right model.
-
What is the issue? Include screenshots / videos if possible!
Model tool keeps placing the same model even though the model it needs to place has changed.
-
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I’ve tried a lot of things, remote events, childadded, they won’t work.
Basically, I have a gui button that changes the model named “Selected”, and then the script should place that model. But the model the script places is the same model as the beginning model, even though the model named “Selected” has changed and is a completely different model.
This method is probably not a good way to do this, but I don’t know how to do it in another way, so if you know a better way to do this, please tell me!
The code:
local Tool = script.Parent
local fire = Tool:WaitForChild("fire")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local function newmodel(player, position, primary, r, t, y)
local model = ReplicatedStorage.Selected:Clone()
model.Parent = game.Workspace
model.PrimaryPart = model.primarypart
local angle = primary.CFrame:ToWorldSpace(CFrame.Angles(math.rad(y), math.rad(r), math.rad(t)))
model:SetPrimaryPartCFrame(angle)
model:MoveTo(position)
end
fire.OnServerEvent:Connect(newmodel)
I don’t understand it very well but I will try to help anyway. Have you tried doing simple debugging?
local Tool = script.Parent
local fire = Tool:WaitForChild("fire")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local function newmodel(player, position, primary, r, t, y)
print("The event got fired by " .. player) -- Deciding to print player firing the event is random, I just wanted to show you to use printing in your code, not only here, but in different scripts to print variables or other information.
local model = ReplicatedStorage.Selected:Clone()
model.Parent = game.Workspace
model.PrimaryPart = model.primarypart
local angle = primary.CFrame:ToWorldSpace(CFrame.Angles(math.rad(y), math.rad(r), math.rad(t)))
model:SetPrimaryPartCFrame(angle)
model:MoveTo(position)
end
fire.OnServerEvent:Connect(newmodel)
Your issue indicates that:
ReplicatedStorage:WaitForChild("Selected"):Clone()
Is always fetching the same model, check the script where the child named “Selected” belonging to the ReplicatedStorage directory is changed.
1 Like
It does get changed, when I look in the Explorer I see the parts of the Selected model change.
Yea sorry I’m not very good at explaining things, but I know everything else works, exept it just does not place the right model it should place. Like when it clones the model, it clones the model that was in the ReplicatedStorage when starting the game, even though I changed that model under the same name with a button. I know it has changed because I can see in the Explorer that the individual parts of the model have changed.
I’ve also tried not cloning the model, and just straight up using the one in the ReplicatedStorage and moving that one. It will place the first model, but if I create another model named “Selected” and put it in ReplicatedStorage, it will cause an error and say: “Selected is not a valid member of “ReplicatedStorage””. But I can clearly see it is a valid member.
This is not in a local script btw. I don’t know if that matters.
Sorry guys I’m still a beginner, but it turns out the problem was that I was only changing the model locally but not on the server.