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

WHAT DID I DO WRONG?! its supposed to give me a gravity coil?! but it does nothing

WHAT DID I DO WRONG, WHEN I PRESS IT IT'S SUPPOSED TO GIVE ME A GRAVITY COIL?! PLEASE TWEAKKKKK.

script:

local player = game.Players.LocalPlayer

script.Parent.MouseButton1Click:Connect(function(click) if player.leaderstats.High Score.Value >= 1 then player.leaderstats.High Score.Value = player.leaderstats.High score - 1

	game.ReplicatedStorage.Tools.GravityCoil:clone().Parent = player:WaitForChild("Backpack")
end

end)

7 comments

1

can you please edit this and put the full script in the code block.

0

It wont let me

0

What do you mean? It won't let you edit?

0

it does let me edit but the code block only does a portion of my script for some reason, and the script that is in the code block is just there by default for some reason

1

You need to fire a remote event. because of the 2017 update for FFE (Force Filtering Enabled), you cannot give commands to the game from a local script. See https://developer.roblox.com/en-us/articles/Remote-Functions-and-Events. Correct me if I am wrong anyone.

0

Ok, so you need to remove the block you already have, then highlight all of your code, then press the code block button.

0

@ yourfuturepilot2 from what I see there, he is cloning it from replicated storage which is accessible from the client because that is where you store remote events.

1 answer

✓ Accepted answer

So. You need to use Remote Events. Because if you're working with GUIs, they have to be LocalScript since they have to be replicated to the PlayerGui. So we're gonna use FireServer() in order to send information. (Make sure your script is below the ScreenGui.)

Local Script

script.Parent.ImageButton:Connect(function()
	local player = game.Players.LocalPlayer
	if player.leaderstats["High Score"].Value >= 1 then
		game.ReplicatedStorage.RemoteEvent:FireServer(player)
	end
end)

Now we just passed data. We only need the player property.

Server Script

game.ReplicatedStorage.OnServerEvent:Connect(function(player)
	player.leaderstats["High Score"].Value = player.leaderstats["High Score"].Value - 1
	local tool = game.ReplicatedStorage.Tools.GravityCoil
	local toolClone = tool:Clone()
	toolClone.Parent = player.Backpack
end)

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