Yes, I know there are a bunch of topics like this, however none of the solutions seemed to help me. Basically, when you trigger a proximity prompt, a part should tween somewhere and a couple values should change. However, while it works fine in studio, nothing happens when playing the actual game.
local button = game.Workspace:WaitForChild("ClothesSwap")
local proximityPrompt = button.TargetA.ProximityPrompt
local value = script.Parent.Parent:WaitForChild("Values"):WaitForChild("mannequin_value")
-- 0 = R15, 1 = R6.
local targetA = button:WaitForChild("TargetA")
local targetB = button:WaitForChild("TargetB")
local targetC = button:WaitForChild("TargetC")
local click = targetA:WaitForChild("ProximityPrompt")
local r6 = targetA:WaitForChild("R6")
local r15 = targetA:WaitForChild("R15")
local tweenInfo = TweenInfo.new(
1, -- Time
Enum.EasingStyle.Sine, -- EasingStyle
Enum.EasingDirection.Out, -- EasingDirection
0, -- RepeatCount (when less than zero the tween will loop indefinitely)
false, -- Reverses (tween will reverse once reaching it's goal)
0 -- DelayTime
)
local tweenToC = game:GetService("TweenService"):Create(targetA, tweenInfo, {CFrame = targetC.CFrame})
local tweenToB = game:GetService("TweenService"):Create(targetA, tweenInfo, {CFrame = targetB.CFrame})
local tweenToA = game:GetService("TweenService"):Create(targetA, tweenInfo, {CFrame = targetA.CFrame})
proximityPrompt.Triggered:Connect(function()
print("Button Triggered")
if value.Value == 1 then
r15.Transparency = 0
r6.Transparency = 1
value.Value = 0
tweenToC:Play()
elseif value.Value == 0 then
r15.Transparency = 1
r6.Transparency = 0
value.Value = 1
tweenToB:Play()
else
print("Error: mannequin_value cannot be changed, try again.")
value.Value = 0
tweenToC:Play()
end
end)
I would try that, but I have already done similar things in the past that didnât require remote events, so I donât think thatâs the issue. Thereâs also the fact that I donât know how to make remote events, lol.
Iâve proof checked your entire script. You have used correct parameters for TweenInfo and so on though as âI_UseAutoParryâ said, :WaitForChild() is certainly a must do. Do use that inside the local script. If that does not work, do tell us the context behind TargetA, TargetB & TargetC, button. What class are they? (Gui, Part, etc)
I have already added the WaitForChild() function, but it didnât work. The three targets are all parts, TargetA is the one being tweened, while B and C are the locations it could be tweened to.
Nope, no errors in Studio. However, in game I get: âTargetA is not a valid member of Model âworkspace.ClothesSwapââ
Sorry I didnât say this before, but I didnât really think to look in the Developer Console for errors.
can you put a new script inside of TargetA and inside of it put
task.wait(1)
print(script.Parent.Parent)
And go into game and check the console, this is just to confirm where itâs located. Maybe its parent is being changed somehow, or itâs being deleted somehow
Sorry I donât really know how to fix this problem, Iâve tried the same script in-game and it worked in studio and in-game so there might be something that makes that part delete or something.
UPDATE: So despite having WaitForChild() on every variable, it turns out that TargetA still wasnât loading fast enough (somehow?). As a last resort because nothing suggested was working, I threw a task.Wait(10) in front of everything. I knew that once the player loaded in, there was no way they could reach the Prompt within 10 seconds, so I figured I could try to give the code more time to load. Sure enough, it worked. Honestly, I have no clue how or why Wait() worked but WaitForChild() didnât, but Iâll take it.
if not game:IsLoaded() then
game.Loaded:Wait()
end
If you put this at the top of the local script, this will force the game to wait until all necessary assets are loaded into the game before running (things such as decal IDs, avatar texture IDs, etc do not count). This usually refers to the client replicating all Instances to the client, even if their texture isnât exactly loaded (if applicable)