Whenever I create a script that involves functions and "game.Players.LocalPlayer." It works when I use it in ** play solo**. When I go to the actual game after publishing it to Roblox, the scripts do not work in the server.
Are there any solutions for this?
function onTouched() if game.Players.LocalPlayer.Character.Shirt.ShirtTemplate ~= 0 then game.Players.LocalPlayer.Character.Shirt.ShirtTemplate = 0 end wait() script.Parent.Search:play() game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 2 wait(5) script.Parent.Search:Pause() game.Players.LocalPlayer.Character.Shirt.ShirtTemplate = "http://www.roblox.com/asset/?id=235795107" game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 16 end script.Parent.Touched:connect(onTouched)
This doesn't really pertain to the actual question, but you do not need a local script to make what you're trying to make. Just use a normal script and put it in the part that you're going to touch.
part = script.Parent template = "" --Copypaste the shirt template. cooldown = false part.Touched:connect(function(hit) if cooldown == false then cooldown = true if game.Players:GetPlayerFromCharacter(hit.Parent) then --We're going to see if there's a player whose character is touching the part. for _, v in pairs(hit.Parent:GetChildren()) do --Let's look through the character model. if v:IsA("Shirt") then v:Destroy() end --If we find a shirt, we DESTROY it. end --Now that we've DESTROYED all the shirts... local shirt = Instance.new("Shirt", hit.Parent) --We clone the new shirt and give it to the character. shirt.ShirtTemplate = template end wait(2) cooldown = false end end)
It only works in studio solo mode since you're using a local script inside of a part, unless your part is a descendant of the player than it should work, but I highly doubt that! LocalScripts don't run if it isn't where is should be, it's like a script in ServerStorage, it won't run at all. The reason it works in studio is because, LocalScripts act like regular scripts in solo. This is to see if your script WOULD work. This is the reason that LocalScripts can use ServerStorage in solo but not in studio. But I mostly think that in solo you're all by yourself and in solo the whole game runs on client. That is the reason it is working in solo mode. I know this because in test mode 2 windows come up, * The Studio where you're testing your game * The SERVER In solo mode there is no server that is being opened.
Solo mode only runs on client side, there is not server since solo runs on client. (I was surprised Goulstem didn't get this :)
Use GetPlayerFromCharacter
to get the player. You don't even need to get the player, all you need is the Character.
script.Parent.Touched:connect(function(part) local h = part.Parent:WaitForChild("Humanoid") if part.Parent:FindFirstChild("Shirt") then part.Parent.Shirt:Destroy() --No shirt, better than changing the ID wait() script.Parent.Search:Play() h.WalkSpeed = 2 wait(5) script.Parent.Search:Stop() --Use Stop not pause to reset the audio every time it plays. h.WalkSpeed = 16 Instance.new("Shirt", part.Parent).ShirtTemplate = "http://www.roblox.com/asset/?id=235795107" end end)
workspace.ShirtChanger.Touched:connect(function() local char = game:GetService("Players").LocalPlayer.Character wait() char.Humanoid.WalkSpeed = 2 char.Shirt:Destroy() workspace.ShirtChanger.Search:Play() wait(5) workspace.ShirtChanger.Search:Stop() char.Humanoid.WalkSpeed = 16 Instance.new("Shirt", char).ShirtTemplate = "http://www.roblox.com/asset/?id=235795107" end)
Hope it helps!