Local Script working in studio, but not in-game

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)
2 Likes

Ok so the skill issue you are having right now is this

So your code is actually correctly written but heres the issue
image
if you run this on studio the GUI might load fast enough for the script to find it and then connect the triggered event

but when you play your game it basically runs this code when the GUI is not loaded there fore it doesnt finds it

Use :WaitForChild() just how you did on the other variables.

3 Likes

Proximity prompts only work on the server side try making an remote event when the player triggers it

2 Likes

Sorry, that didn’t work for me.

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.

1 Like

If you dont know how to make remote events then you should learn how to they are pretty essential to roblox development

1 Like

Like I said though, I have already done the exact same thing in Studio before so it should be working without the help of remote events.

1 Like

Proximity prompts work locally as well. You’re confusing yourself with local script limitations.

Could you tell us where the local script is located?

The local script is a descendant of the local player’s Player Scripts.

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.

Were there any errors in the console in the game?

Also, I tested this script and it worked fine in studio and in-game.

1 Like

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.

Is ‘TargetA’ anchored? And is CanCollide false?

1 Like

Yes and yes. This is one of the weirdest things that has ever happened to me, lol…

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

1 Like

In both Studio and In-Game, it prints ‘ClothesSwap’, so it must be in the right place.

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.

1 Like

it apppears I had a skill issue momment and read that as a gui button and not a proximity prompt, my bad guys.

2 Likes

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)

1 Like